Subject: [xsl] Merging elements within a range using a key From: "Mike B" <mikeb0304@xxxxxxxxxxx> Date: Mon, 01 May 2006 19:48:15 -0500 |
Simplified Input document ------------------------------------ <view> <results> <row r="20"> <col c="1">col 20.1 data</col> </row> <row r="21"> <col c="1">col 21.1 data</col> </row> <row r="22"> <col c="1">col 22.1 data</col> </row> </results> <category> <category s="18" e="19">cat a</category> <category s="20" e="21">cat b</category> <category s="22" e="25">cat c</category> </category> </view>
Output document ------------------------ <view> <results> <category s="20" e="21">cat b <row r="20"> <col c="1">col 20.1 data</col> </row> <row r="21"> <col c="1">col 21.1 data</col> </row> </category> <category s="22" e="25">cat c <row r="22"> <col c="1">col 22.1 data</col> </row> </category> </results> </view>
<xsl:template match="/view"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> <xsl:copy-of select="/view/category" /> </xsl:copy> </xsl:template>
<xsl:template match="results"> <!-- do not copy old results to output --> </xsl:template>
<xsl:template match="/view/category"> <xsl:element name="results"> <xsl:call-template name="copy-attributes"> <xsl:with-param name="attributes" select="@*" /> </xsl:call-template> <xsl:call-template name="copy-attributes"> <xsl:with-param name="attributes" select="/view/results/@*" /> </xsl:call-template> <xsl:apply-templates select="category" /> </xsl:element>
<xsl:if test="string-length($row-test) > 0"> <xsl:choose> <xsl:when test="category">
<xsl:element name="{name()}"> <xsl:call-template name="copy-attributes"> <xsl:with-param name="attributes" select="@*" /> </xsl:call-template> <xsl:value-of select="text()" />
</xsl:element> </xsl:when>
<xsl:otherwise> <xsl:element name="{name()}"> <xsl:call-template name="copy-attributes"> <xsl:with-param name="attributes" select="@*" /> </xsl:call-template> <xsl:value-of select="text()" />
<xsl:copy-of select="$row-test" /> </xsl:element> </xsl:otherwise> </xsl:choose> </xsl:if>
<xsl:template name="copy-attributes"> <xsl:param name="attributes" />
<xsl:for-each select="$attributes"> <xsl:attribute name="{name()}"> <xsl:value-of select="." /> </xsl:attribute> </xsl:for-each>
<xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] treating variables like n, Esha Datta | Thread | RE: [xsl] Merging elements within a, Michael Kay |
Re: [xsl] chekcing attribute exista, jd list | Date | [xsl] XSL to output new XML documen, Gary E. Daniels |
Month |