RE: [xsl] Re: Wrapping problem

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"

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

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

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

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

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


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

Current Thread