xsl-list
[Top] [All Lists]

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

2007-08-08 04:03:37
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.

--~------------------------------------------------------------------
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>
--~--