Reputation: 47
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.
Upvotes: 0
Views: 492
Reputation: 70648
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">
Upvotes: 1