Xslt Value Of in XML
? Using <xsl:value-of> in XSLT (XML)
<xsl:value-of> is used to extract and output the string value of an XML node or expression during an XSLT transformation.
Basic Syntax
<xsl:value-of select="XPath-expression"/>The
selectattribute contains an XPath expression pointing to the node or value you want.It outputs the text content of the selected node.
Example
Input XML
<person> <name>John Doe</name> <age>30</age></person>XSLT using <xsl:value-of>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/person"> <div> Name: <xsl:value-of select="name"/><br/> Age: <xsl:value-of select="age"/> </div> </xsl:template></xsl:stylesheet>Output
<div> Name: John Doe<br/> Age: 30</div>Notes
Outputs only the first node’s string value if the XPath matches multiple nodes.
To output multiple nodes, use it inside
<xsl:for-each>or multiple templates.For raw XML output, use
<xsl:copy-of>instead.
Want an example showing how to use <xsl:value-of> with expressions or concatenation?