Subject: [xsl] Insert new element depending on value of attribute From: Gerhard Glatz <Gerhard21@xxxxxxx> Date: Mon, 18 Feb 2008 19:10:51 +0100 |
<root> <disk> <tracks> <track> <multipart></mulitpart> <length></length> <measure></measure> </track> <track> <length></length> <measure></measure> </track> </tracks> <disk> <disk> <tracks> <track> <length></length> <measure></measure> </track> <track> <length></length> <measure></measure> </track> </tracks> <tracks> <track> <length></length> <measure></measure> </track> <track> <multipart></mulitpart> <length></length> <measure></measure> </track> </tracks> <disk> </root>
What the lines below do: - Copy all nodes - Insert a new element <track> in every <disk> at the last position
<xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()" /> </xsl:copy> </xsl:template>
<xsl:template match="/root/disk/tracks/track"> <xsl:copy> <xsl:apply-templates select="@*|node()" /> </xsl:copy>
<xsl:if test="position()=last()"> <xsl:element name="track"> <xsl:attribute name="length">....</xsl:attribute> ... </xsl:element>
</xsl:if> </xsl:template>
Does anybody have a hint, where and how I should add something like <xsl:if test="multipart/@attribute=desired_value"> ??
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] defining output document , James Sulak | Thread | Re: [xsl] Insert new element depend, Martin Honnen |
RE: [xsl] Complex recursion in XSLT, Michael Kay | Date | Re: [xsl] Insert new element depend, Martin Honnen |
Month |