0

My xml looks like: myXml.xml

<root>
<element1>x,y,z</element1>
<element2>a,b,c</element2>
<element3>p,a,q</element3>
<element4>y,g,h</element4>
</root>

I am trying to retrive the value of element with xsl query like:

<xsl:variable name="myXml" select="document(myXml.xml)/root"/>

and then retrival of say element1 with:

<xsl:variable name="element1-val" select="$myXml/local-name()='element1'/@value"/>

It is not retruning expected value : x,y,z

1 Answer 1

1

You're missing some quotes:

<xsl:variable name="myXml" select="document('myXml.xml')/root"/>

You need to load the file named myXml.xml, whereas your code in the question is attempting to load the file whose name is given by the value of the <myXml.xml> child element of the current context node (which doesn't exist, of course).

You're also missing some brackets:

<xsl:variable name="element1-val" select="$myXml/*[local-name()='element1']/@value"/>

but in fact you don't need the local-name trick at all, just

<xsl:variable name="element1-val" select="$myXml/element1/@value"/>

would work just fine.

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.