[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] creating nested structure using the following styleshe
Hello List!
I need to create a nested structure from the following source: <root> <element> <h1>h1</h1> <h2>h2</h2> <para>para</para> <para>para<emp>auszeichnung</emp></para> <para>para</para> <para>para</para> <para>para</para> <h2>h2</h2> <para>para</para> <h3>h3</h3> <para>para</para> <h5>h5</h5> <para>para</para> <para>para<emp>auszeichnung</emp></para> <para>para</para> <h4>h4</h4> <para>para</para> <para>para</para> <h2>h2</h2> <para>para</para> <para>para</para> <para>para</para> <h3>h3</h3> <para>para<emp>auszeichnung</emp></para> <para>para</para> <para>para</para> <h4>h4</h4> <para>para</para> <para>para</para> <h5>h5</h5> <para>para</para> <para>para<emp>auszeichnung</emp></para> <para>para</para> </element> </root> For output I use this stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output indent="yes"/> <xsl:template match="/"> <set> <book> <bookinfo/> <xsl:apply-templates/> </book> </set> </xsl:template> <xsl:template match="element"> <xsl:apply-templates select="h1|h2[1]"/> </xsl:template> <xsl:template match="h1"> <title> <xsl:apply-templates/> </title> </xsl:template> <xsl:template match="h2"> <chapter> <title> <xsl:apply-templates/> </title> <xsl:for-each-group select=".|following-sibling::*" group-starting-with="h2|h3|h4|h5"> <xsl:variable name="para-content"> <xsl:copy-of select="current-group()[self::para]"/> </xsl:variable> <xsl:choose> <xsl:when test="position()=1"> <xsl:copy-of select="current-group()[self::para]"/> </xsl:when> <xsl:when test="current-group()[name()='h2']"> <title> <xsl:apply-templates/> </title> <xsl:copy-of select="$para-content"/> </xsl:when> <xsl:when test="current-group()[name()='h3']"> <xsl:element name="sect{number(substring-after(name(.),'h'))-2}"> <title> <xsl:apply-templates/> </title> <xsl:copy-of select="$para-content"/> </xsl:element> </xsl:when> <xsl:when test="current-group()[name()='h4']"> <xsl:element name="sect{number(substring-after(name(.),'h'))-2}"> <title> <xsl:apply-templates/> </title> <xsl:copy-of select="$para-content"/> </xsl:element> </xsl:when> <xsl:when test="current-group()[name()='h5']"> <xsl:element name="sect{number(substring-after(name(.),'h'))-2}"> <title> <xsl:apply-templates/> </title> <xsl:copy-of select="$para-content"/> </xsl:element> </xsl:when> </xsl:choose> </xsl:for-each-group> </chapter> </xsl:template> </xsl:stylesheet>
A second question: the emp element inside a para will not match when I use <xsl:template match="emp"> <emphasis role="bold"> <xsl:apply-templates/> </emphasis> </xsl:template> Is this because para is inside a xsl:for-each-group? Thanks for helping me, Andreas
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|