RE: [xsl] Taking flat XML and parsing into multi level nexted

Subject: RE: [xsl] Taking flat XML and parsing into multi level nexted
From: christoph.naber@xxxxxxxxxxxxxxxxxxx
Date: Wed, 08 Aug 2007 13:01:50 +0200
Hello Paul,

I just tried to find a solution for your problem in XSLT 1.0, and I came
up with this:

<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform";>
        <xsl:output method="xml" indent="yes"/>

        <xsl:template match="/root" >
                <root>
                        <xsl:apply-templates select="*[1]" />
                </root>
        </xsl:template>

        <xsl:template match="item">
                <item>
                        <title><xsl:value-of select="text()" /></title>
                </item>
                <xsl:apply-templates
select="following-sibling::*[1][not(self::categoryEnd)]" />
        </xsl:template>

        <xsl:template match="categoryStart">
                <xsl:variable name="thisName" select="text()" />
                <group>
                        <title><xsl:value-of select="text()" /></title>
                        <xsl:apply-templates
select="following-sibling::*[1][not(self::categoryEnd)]" />
                </group>
                <xsl:apply-templates
select="following-sibling::*[preceding-sibling::*[1][self::categoryEnd and
text() = $thisName]]" />
        </xsl:template>

        <xsl:template match="*" />

</xsl:stylesheet>

I hope this doesn't induce "hurting eyes" to some of the professionals
here, but it does the work with the given sample input.

Greetings
Christoph


If you are not the intended addressee, please inform us immediately that you
have received this e-mail by mistake and delete it. We thank you for your
support.

Current Thread