Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Trouble with XSL

From: carra@--.---.---
To: NULL
Date: 1/3/2007 3:01:00 AM


p.lepin@c... wrote:

> carra@u... wrote:
> > If I have some XML that looks like this...
>
> No you don't. That's not XML. Where's the root element?
>
> > <heading1>fdfdfdfdf</heading>
>
> For that matter, this is not well-formed.
>
> > <para>text1</para>
> > <para>text2</para>
> > <table>Table structure</table>
> > <para>text3</para>
> > <heading2>gfhgjg</heading>
>
> Neither is this.
>
> > <para>text4</para>
>
> So you can't be bothered to spend fifteen minutes reading
> XSLT/XPath tutorial, you can't be bothered to spend fifteen
> *seconds* proof-reading your post, and you're asking for
> help. Ok then.
>
> > How do I transform it with XSL so that all the para's and
> > tables under the headings are wrapped within the heading
> > so that it looks like this....
> >
> > <heading1>
> >    <para>text1</para>
> >    <para>text2</para>
> >    <table>Table structure</table>
> >    <para>text3</para>
> > </heading>
> > <heading2>
> >    <para>text4</para>
> > </heading2>
>
> Since you failed to mention what should happen to headings'
> children and attributes, I won't address that.
>
> Here's a little something for you to chew on. Have fun:
>
> <xsl:stylesheet version="1.0"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>   <xsl:key
>     name="heading"
>     match="*[not(starts-with(local-name(),'heading'))]"
>     use=
>     "
>       generate-id
>       (
>         preceding-sibling::*
>           [starts-with(local-name(),'heading')][1]
>       )
>     "/>
>   <xsl:template match="@*|node()">
>     <xsl:copy>
>       <xsl:apply-templates select="@*|node()"/>
>     </xsl:copy>
>   </xsl:template>
>   <xsl:template
>     match="*[starts-with(local-name(),'heading')]">
>     <xsl:copy>
>       <xsl:apply-templates
>         select="key('heading',generate-id())" mode="copy"/>
>     </xsl:copy>
>   </xsl:template>
>   <xsl:template
>     match=
>     "
>       *
>         [not(starts-with(local-name(),'heading'))]
>         [
>           preceding-sibling::*
>             [starts-with(local-name(),'heading')]
>         ]
>     "/>
>   <xsl:template match="@*|node()" mode="copy">
>     <xsl:copy>
>       <xsl:apply-templates select="@*|node()" mode="copy"/>
>     </xsl:copy>
>   </xsl:template>
> </xsl:stylesheet>
>
> --
> Pavel Lepin

That's a big help people, thanks a lot.

BTW I forgot to mention the XML I used was an example fragment, not
real code, so forgive typo's.
No need to get abusive though, eh Pavel.



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent