[Home] [By Thread] [By Date] [Recent Entries]
for-each-group is the answer to almost anything (next to 42, of course).
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://saxon.sf.net/" version="2.0" exclude-result-prefixes="saxon"> <xsl:output
method="xml"
indent="yes"
saxon:suppress-indentation="product"
/><xsl:template match="*[starts-with(name(), 'level')]"> <xsl:variable name="level-name" select="name()" /> <xsl:for-each-group select="*" group-starting-with="item"> <xsl:choose> <xsl:when test="current-group()[1]/self::item"> <xsl:element name="{replace($level-name, 'level', 'step')}"> <text> <para> <xsl:apply-templates select="current-group()[1]/node()" /> </para> </text> <xsl:apply-templates select="current-group()[position() gt 1]" /> </xsl:element> </xsl:when> <xsl:otherwise> <warning> <para>There should be an item in the source at this point.</para> </warning> <!-- <xsl:copy-of select="current-group()" /> --> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:template> <xsl:template match="product[not(name(preceding-sibling::*[1]) = ('item', 'product'))]"> <warning> <para>Dangling product in the source: <xsl:value-of select="."/> </para> </warning> </xsl:template> <xsl:template match="@* | *" priority="-1">
<xsl:copy>
<xsl:apply-templates select="@* | * | text()" mode="#current" />
</xsl:copy>
</xsl:template></xsl:stylesheet> a kusa schrieb: My output must look like this:
Registergericht / Commercial Register: Amtsgericht Leipzig Registernummer / Registration Number: HRB 24930 Geschdftsf|hrer: Gerrit Imsieke, Svea Jelonek, Thomas Schmidt, Dr. Reinhard Vvckler
|

Cart



