user3719454
user3719454

Reputation: 1024

What's the difference between the following two XSLT expressions?

What is the difference between these expressions?

<xsl:text>someValue</xsl:text>

<xsl:value-of select="'someValue'"/>

And which to use?

Upvotes: 0

Views: 48

Answers (2)

Jean-Fran&#231;ois Savard
Jean-Fran&#231;ois Savard

Reputation: 21004

<xsl:value-of select=""/> element is used to extract the value of a selected node.

The <xsl:text> element is used to write literal text to the output. This element may contain literal text, entity references, and #PCDATA.

Note that in your exemple, both will return the same as you specify to select the text 'someValue', but I tought it would be nice to tell you the difference between both.

Upvotes: 1

Martin Honnen
Martin Honnen

Reputation: 167581

Both <xsl:text>someValue</xsl:text> and <xsl:value-of select="'someValue'"/> create a text node with the contents someValue so there is no difference and if you want to output a literal text it is up to you which form you prefer. Of course in general value-of and its select attribute allow you the use of an XPath expression of any type, so in case you don't want to output a string hard coded in XSLT you would use value-of.

Upvotes: 1

Related Questions