How to concat a string to xsl:value-of select="...?

Hanumanth picture Hanumanth · May 1, 2012 · Viewed 274.5k times · Source
<a>
    <xsl:attribute name="href"> 
     <xsl:value-of select="/*/properties/property[@name='report']/@value" />
    </xsl:attribute>
</a>    

Is there any way to cancat another string to

<xsl:value-of select="/*/properties/property[@name='report']/@value"  />

I need to pass some text to href attribute in addition to the report property value

Answer

Tim C picture Tim C · May 1, 2012

You can use the rather sensibly named xpath function called concat here

<a>
   <xsl:attribute name="href">
      <xsl:value-of select="concat('myText:', /*/properties/property[@name='report']/@value)" />
   </xsl:attribute>
</a>  

Of course, it doesn't have to be text here, it can be another xpath expression to select an element or attribute. And you can have any number of arguments in the concat expression.

Do note, you can make use of Attribute Value Templates (represented by the curly braces) here to simplify your expression

<a href="{concat('myText:', /*/properties/property[@name='report']/@value)}"></a>