0

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
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Peter
  • 1,786
  • 4
  • 21
  • 40
  • what's the context? can you post your whole xslt path? what xslt processor are you using? a reproducible example would really help. If you are interested in the 2013... string, why did you include the contentVersion node? – Alex Brown Jan 15 '14 at 06:48

2 Answers2

2

Whoops, just edited my answer:

<xsl:variable name="vtextPostM" select="order/child::node()[position()=1][self::text()]"/>
Joel M. Lamsen
  • 7,143
  • 1
  • 12
  • 14
1

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>.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • Hello Michael, thank you. I will go with your solution. My mistake was that I did not consider the current node (order) properly in my XPATHs. Lesson learnt. Best regards, PEter – Peter Jan 15 '14 at 10:09