0

I am presented with this XML code below. What is the XSLT syntax to access the value of the key "var2"?

.
.
<array key = "objects">
    <map>
        <string key "var1">ID</string>
        <string key "var2">Name</string>
        <string key "var3">Weather</string>
    <map>
</array>
.
.

I'm no XSLT expert, but I'm familiar in my XSLT work with XML variables and intending to assign the value of "var2" in a variable to display in my translated document.

1 Answer 1

1

It really depends what your current position is in the XML, but to access it for anywhere you could do this...

<xsl:variable name="var2" select="//array/map/string[@key='var2']" />

Or, if you have multiple array objects, and want to target a specific one...

<xsl:variable name="var2" select="//array[@key='objects']/map/string[@key='var2']" />

(Note, I've assumed your actual XML is valid XML, as it should be <string key="var2"> and not <string key "var2">

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.