xsl-list
[Top] [All Lists]

Re: [xsl] Re: Wrapping problem

2006-08-15 04:57:24
Thanks Mike..

On 8/15/06, Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:
> Hi Mike,
>    Can you please post this approach in more detail. I am not
> able to find anything about it on google.
>

Since you insist:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

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

<xsl:template match="/play">
 <play>
   <xsl:apply-templates select="scene" />
 </play>
</xsl:template>

<xsl:template match="scene">
 <scene name="{.}">
   <xsl:apply-templates select="following-sibling::character[1]"/>
 </scene>
</xsl:template>

<xsl:template match="character">
   <character name="{.}">
       <xsl:apply-templates select="following-sibling::*[1][self::line]"/>
   </character>
   <xsl:apply-templates
select="following-sibling::*[self::character|self::scene][1][self::character
]"/>
</xsl:template>

<xsl:template match="line">
   <xsl:copy-of select="."/>
   <xsl:apply-templates select="following-sibling::*[1][self::line]"/>
</xsl:template>

</xsl:stylesheet>

I call the technique "sibling recursion". It's more concise than most
recursive code, because it's self-terminating: you don't need to test
explicitly whether there are more items to process, because apply-templates
does that automatically for you.

Michael Kay
http://www.saxonica.com/

--
Regards,
Mukul Gandhi

http://gandhimukul.tripod.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>