In my XSL file, with this command I
get both the contents of tag1 and the
contents of tag2 printed:
<xsl:value-of select="tag1"/>
How can I get just the first, higher
level, string?
Your code produces the string value of the tag1
element, which by definition is the concatenation of all text-nodes-descendents of the element.
To produce just
the "Print this" string
you need to specify an XPath expression that selects only the respective text node:
/tag1/text()[1]
Specifying [1]
is necessary to select only the first text-node child, otherwise two text-nodes may be selected (this is an issue only in XSLT 2.0 where <xsl:value-of>
produces the string values of all nodes specified in the select
attribute).
Further, the above expression selects the whole text node and its string value isn't "Print this"
.
The string value actually is:
"
Print this
"
and exactly this would be output if you surround the <xsl:value-of>
in quotes.
To produce exactly the wanted string "Print this"
use:
"<xsl:value-of select="normalize-space(/tag1/text()[1])"/>"