Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xslt

xpath

<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

like image 349
Hanumanth Avatar asked May 01 '12 08:05

Hanumanth


People also ask

How do I concatenate values in XSLT?

The Concat function takes two input strings as a source and concatenates them defined in XPATH. Below we shall see the arguments it returns and it is very easy to accomplish with XSLT. concat('x') – Gives out error as it got one single string value. Concat('x',' y') – This returns xy.

What does xsl value of select /> mean in an xsl file?

Definition and Usage The <xsl:value-of> element extracts the value of a selected node. The <xsl:value-of> element can be used to select the value of an XML element and add it to the output.

How do I add text to XSLT?

You could add an empty template to ignore any pre-existing text within the attr element: <xsl:template match="attr[@tag='00080090']/text()"/> . Or you could omit node() in the last select attribute (assuming you only want to copy the attributes of the attr element, not any content).


2 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> 
like image 187
Tim C Avatar answered Sep 21 '22 12:09

Tim C


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')}" /> 
like image 45
Ninjanoel Avatar answered Sep 21 '22 12:09

Ninjanoel