Insert value using XSLT

I have a tag and I need to assign a value to its attribute in my XSLT

<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> 

I need to assign a value to the trId attribute, but the way I don't work it now is, What is the correct way to do this?

 <ABX trId="<xsl:value-of select="CODE_VALUE"/>"> </xsl:template> </xsl:stylesheet> 
+6
xslt
source share
2 answers
 <ABX> <xsl:attribute name="trId"><xsl:value-of select="CODE_VALUE"/></xsl:attribute> </ABX> 

The XSLT <attribute > tag will do exactly what you want.

+10
source share

Or you could just do this:

 <ABX trId="{CODE_VALUE}"/> 

The expression inside the curly braces is evaluated, and the result is placed in the attribute value. See Section 7.6.2, Attribute Value Templates in the specification.

+5
source share

All Articles