Subject: Re: [xsl] <xsl:attribute issue From: Abel Braaksma <abel.online@xxxxxxxxx> Date: Wed, 16 May 2007 13:59:22 +0200 |
Hi, I am trying to create an attribute for one of my xml files that has a typoical format like: <root> <level1> <name>Name1</name> other tags </level1> <level1> <name>Name2</name> other tags </level1> </root>
so I'm trying to set the attribute of the name element before displaying it:
<xsl:for-each select=level1> <xsl:variable ....{here I get a variable so that's why I can't call directly for each level1/name>
<xsl:for-each select="name"> <xsl:attribute name="test"> <xsl:value-of select="4"/>(just for testing, instead of 4 I have a variable but I put 4 for testing) </xsl:attribute> <xsl:for-each> </xsl:for-each>
and then if I try to display it using
<xsl:for-each select="level1/name">
<xsl:value-of select="@test"/>
</xsl:for-each>,
it doesn't display anything.
You create an attribute like this: <xsl:attribute name="bla">value</xsl:attribute>
but it must be a direct child of an element, like this: <lre-element> <xsl:attribute name="bla">value</xsl:attribute> </lre-element>
if the value is literate, you don't need to use xsl:attribute <lre-element bla="value" />
Good luck coding -- Abel Braaksma
<xsl:template match="node() | @*"> <xsl:copy><xsl:apply-templates select="node() | @*" /></xsl:copy> </xsl:template>
<xsl:template match="name"> <xsl:copy> <xsl:attribute name="test">4</xsl:attribute> <xsl:apply-templates select="node() | @*" / </xsl:copy> </xsl:template>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] <xsl:attribute issue, Vaduvoiu Tiberiu | Thread | RE: [xsl] <xsl:attribute issue, Michael Kay |
Re: [xsl] Calling a java method in , Abel Braaksma | Date | [xsl] Help with 3-level deep XML, Bhaskar |
Month |