0

I am trying to store the following list in xml into a variable

<Locations>
  <Location>A1</Location>
  <Location>A2</Location>
  <Location>A3</Location>
  <Location>C1</Location>
  <Location>C2</Location>
</Locations>

this is my xsl code

<xsl:variable name="my_locations" select="*/text()"/>

I verified that */text() contains all the string location values via visual studio debugger

but my_locations still seems to be empty

I have to use xsl stylesheet version 1.0 for my task

please advise

1 Answer 1

1

Your XPath */text(), because it doesn't start with a /, is evaluated relative to a "context node" (i.e. a current node). Depending on where your xsl:variable statement that context node could be anything. You should really have provided a minimal reproducible example, for your question.

Let's assume that the xsl:variable is a child element of the xsl:stylesheet; in that case, typically the context node is the document node of the input document, and the path will return text nodes which are children of the root element, as if your XPath were /*/text(). However, the text nodes you are after are not children of the root element; they are children of the child elements of the root element.

Try this instead:

<xsl:variable name="my_locations" select="/Locations/Location/text()"/>

or just

<xsl:variable name="my_locations" select="//Location/text()"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.