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

April 2024 ยท 2 minute read
<a> <xsl:attribute name="href"> <xsl:value-of select="/*/properties/property[@name='report']/@value" /> </xsl:attribute> </a> 

Is there any way to concat 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

0

6 Answers

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> 
2

Three Answers :

Simple :

<img> <xsl:attribute name="src"> <xsl:value-of select="//your/xquery/path"/> <xsl:value-of select="'vmLogo.gif'"/> </xsl:attribute> </img> 

Using 'concat' :

<img> <xsl:attribute name="src"> <xsl:value-of select="concat(//your/xquery/path,'vmLogo.gif')"/> </xsl:attribute> </img> 

Attribute shortcut as suggested by @TimC

<img src="{concat(//your/xquery/path,'vmLogo.gif')}" /> 
1

Use:

<a href="wantedText{/*/properties/property[@name='report']/@value)}"></a> 

The easiest way to concat a static text string to a selected value is to use element.

<a> <xsl:attribute name="href"> <xsl:value-of select="/*/properties/property[@name='report']/@value" /> <xsl:text>staticIconExample.png</xsl:text> </xsl:attribute> </a> 

Easiest method is

 <TD> <xsl:value-of select="concat(//author/first-name,' ',//author/last-name)"/> </TD> 

when the XML Structure is

<title>The Confidence Man</title> <author> <first-name>Herman</first-name> <last-name>Melville</last-name> </author> <price>11.99</price> 

Not the most readable solution, but you can mix the result from a value-of with plain text:

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

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoaGlraWqBeYSOoaawZaSkeqS7zZyYrWWRYsC1vsinnmasn2LFtLjVmqOunV2ks26%2FxKWcnKw%3D