Announcement

Collapse
No announcement yet.

Problem mit for-each-group

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem mit for-each-group

    Hallo,

    ich habe ein kleines Problem mit for-each-group:

    Als Input habe ich folgendes:

    <html>
    <head>
    <title>testTitle</title>
    </head>
    <body>
    <chapter>
    <h1>Loomings</h1>
    <p>par 1</p>
    <p>par 2</p>
    <p>par 3</p>
    <h1>The Whiteness of the Whale</h1>
    <p>par 4</p>
    <p>par 5</p>
    <p>par 6</p>
    </chapter>
    </body>
    </html>

    Mein XSL sieht wie folgt aus:
    <?xml version="2.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xslutput method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/>

    <xsl:template match="html">
    <xsl:element name="ZZ">
    <xsl:element name="YY">
    <xsl:apply-templates select="/html/body"/>
    </xsl:element>
    </xsl:element>
    </xsl:template>

    <xsl:template match="/html/body">
    <body>
    <xsl:for-each-group select="*" group-starting-with="h1">
    <chapter>
    <xsl:for-each select="current-group()">
    <xsl:copy>
    <sub_chapter>
    <xsl:element name="AA">
    <xsl:value-of select="h1"/>
    </xsl:element>
    <xsl:element name="BB">
    <xsl:value-of select="p"/>
    </xsl:element>
    </sub_chapter>
    </xsl:copy>
    </xsl:for-each>
    </chapter>
    </xsl:for-each-group>
    </body>
    </xsl:template>
    </xsl:stylesheet>

    Wenn ich dies oben auf das XML anwende, dann erhalte ich folgendes:
    <?xml version="1.0" encoding="UTF-8"?>
    <ZZ>
    <YY>
    <body xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <chapter>
    <chapter>
    <sub_chapter>
    <AA>Loomings The Whiteness of the Whale</AA>
    <BB>par 1 par 2 par 3 par 4 par 5 par 6</BB>
    </sub_chapter>
    </chapter>
    </chapter>
    </body>
    </YY>
    </ZZ>


    Hatte eigentlich gehofft, dies zu erhalten:
    <?xml version="1.0" encoding="UTF-8"?>
    <ZZ>
    <YY>
    <body xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <chapter>
    <sub_chapter>
    <AA>Loomings The Whiteness of the Whale</AA>
    <BB>par 1</BB>
    <BB>par 2</BB>
    <BB>par 3</BB>
    </sub_chapter>
    <sub_chapter>
    <AA>The Whiteness of the Whale</AA>
    <BB>par 4</BB>
    <BB>par 5</BB>
    <BB>par 6</BB>
    </sub_chapter>
    </chapter>
    </body>
    </YY>
    </ZZ>


    Kann mir da jemand weiter helfen? Was muss ich in meinem xsl anders schreiben?

    LG
Working...
X