Subject: RE: [xsl] Re: Wrapping problem From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Tue, 15 Aug 2006 12:06:35 +0100 |
> 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/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Re: Wrapping problem, Mukul Gandhi | Thread | Re: [xsl] Re: Wrapping problem, Mukul Gandhi |
Re: [xsl] Re: Wrapping problem, Mukul Gandhi | Date | Re: [xsl] Re: Wrapping problem, Mukul Gandhi |
Month |