How can I get a value from an xml key/value pair with xpath in my xslt?

Posted by TahoeWolverine on Stack Overflow See other posts from Stack Overflow or by TahoeWolverine
Published on 2010-04-29T14:26:18Z Indexed on 2010/04/29 15:07 UTC
Read the original article Hit count: 375

Filed under:
|
|

I have some xml that I want to process using xslt. A good amount of the data comes through in key value pairs (see below). I am struggling with how to extract the value base on the key into a variable. I would like to be able to do something like this:

<xsl:variable name="foo" select="/root/entry[key = 'foo']/value"/>

but that doesn't seem to work. Here is sample xml.

<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
  <entry>
    <key>
      foo
    </key>
    <value>
      bar
    </value>
  </entry>
</root>

What would the correct xpath be for this?

© Stack Overflow or respective owner

Related posts about xpath

Related posts about Xml