Reputation: 1796
I am having the same problem as described in How to get text from the node in xml file, that contains text and child node? but I need XSLT to match the text.
I have the following simplified XML:
<?xml version="1.0" encoding="UTF-8"?>
<order>2013-09-02T00:00:00COPY
<contentVersion>
<versionIdentification>2.1.1</versionIdentification>
</contentVersion>
</order>
I have tried the following XPATHs:
<xsl:variable name="vtextPostM" select="text()[self::order]"/>
<xsl:variable name="vtextPostM" select="self::text()[1]"/>
<xsl:variable name="vtextPostM" select="text()[self::*]"/>
I am expecting:
2013-09-02T00:00:00COPY
Upvotes: 0
Views: 231
Reputation: 7173
Whoops, just edited my answer:
<xsl:variable name="vtextPostM" select="order/child::node()[position()=1][self::text()]"/>
Upvotes: 2
Reputation: 116993
Where exactly are you when you define the variable? Without any context, the absolute path:
/order/text()[1]
or just (using your specific example):
/order/text()
should produce the result you want. You will want to wrap this in a normalize-space(), because it includes the trailing line feed before <contentVersion>
.
Upvotes: 1