Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Help needed with transition

From: Mukul Gandhi <mukul_gandhi@-----.--->
To: NULL
Date: 11/19/2008 1:07:00 AM
David has given both a 2.0 and a 1.0 solution. I wouldn't write
anything different for what David wrote for XSLT 2.0.

But here's a slightly different 1.0 solution,

<xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
                       version=3D"1.0">

 <xsl:output method=3D"xml" indent=3D"yes" />

 <xsl:template match=3D"x">
   <result>
     <xsl:apply-templates select=3D"field[heading]" mode=3D"a" />
   </result>
 </xsl:template>

 <xsl:template match=3D"field" mode=3D"a">
   <fieldset>
     <legend><xsl:value-of select=3D"heading" /></legend>
     <xsl:apply-templates select=3D"following-sibling::field[1][text]"
mode=3D"b" />
   </fieldset>
 </xsl:template>

 <xsl:template match=3D"field" mode=3D"b">
   <p><xsl:value-of select=3D"text" /></p>
   <xsl:apply-templates select=3D"following-sibling::field[1][text]"
mode=3D"b" />
 </xsl:template>

</xsl:stylesheet>

this is popularly known as the sibling recursion technique.

Cheers,
Mukul

On Nov 19, 2:40=A0am, "Hvid Hat" <hvid....@please-no-mail.thx> wrote:
> Hi
>
> Can anyone help me with the following transition? My problem is how to cr=
eate
> a fieldset each time I run into a heading and then include the following =
text
> elements within the fieldset.
>
> <?xml version=3D"1.0" encoding=3D"ISO-8859-1"?>
> <field>
> =A0 <heading>First heading</heading>
> </field>
> <field>
> =A0 <text>Lorem</text>
> </field>
> <field>
> =A0 <text>Ipsum</text>
> </field>
> <field>
> =A0 <heading>Second heading</heading>
> </field>
> <field>
> =A0 <text>Dolor</text>
> </field>
> <field>
> =A0 <text>Sit</text>
> </field>
> <field>
> =A0 <heading>Third heading</heading>
> </field>
> <field>
> =A0 <text>Amet</text>
> </field>
>
> To
>
> <fieldset>
> =A0 <legend>First heading</legend>
> =A0 <p>Lorem</p>
> =A0 <p>Ipsum</p>
> </fieldset>
> <fieldset>
> =A0 <legend>Second heading</legend>
> =A0 <p>Dolor</p>
> =A0 <p>Sit</p>
> </fieldset>
> <fieldset>
> =A0 <legend>Third heading</legend>
> =A0 <p>Amet</p>
> </fieldset>


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