In my XSL file with this command, I get both the contents of tag1 and the contents of the printed tag2:
<xsl:value-of select="tag1"/>
How can I get only the first, higher level, string?
The code creates the string value of the tag1 element, which by definition is the concatenation of all text nodes-descendants of the element.
To create only
print this line
you need to specify an XPath expression that selects only the corresponding node text :
/tag1/text()[1]
Task [1] necessary to select only the first text node, otherwise two text nodes may be selected (this is a problem only in XSLT 2.0, where <xsl:value-of> creates string values โโof all specified nodes in the select attribute).
In addition, the above expression selects the entire text node, and its string value is not "Print this" .
The string value is actually:
" Print this "
and this is what will be output if you surround the <xsl:value-of> in quotation marks.
To create the desired line "Print this" , use :
"<xsl:value-of select="normalize-space(/tag1/text()[1])"/>"
source share