Oleg_08
Oleg_08

Reputation: 487

How to adress a certain parameter of the element in the value of select in XSLT?

My XML is following:

<tags>
      <tag id="2">
        <name>
          <de-DE>xxx</de-DE>
        </name>
      </tag>
      <tag id="5">
        <name>
          <de-DE>ccc</de-DE>
        </name>
      </tag>
      <tag id="12">
        <name>
          <de-DE>CC BY-SA</de-DE>
        </name>
      </tag>
    </tags>

I need to extract CC BY-SA from the tag id="12". How can I adress tag id="12" with a value of select command. That's what I tried to do, but it extracts nothing:

 <xsl:value-of select="/tags/tag[@id=12]/name/de-DE"/>  

Upvotes: 0

Views: 68

Answers (1)

kumesana
kumesana

Reputation: 2490

With the XML you give as example, what you tried is correct. You can check it with any XSLT online tool.

However I entertain the possibility that the example you give is not exactly what you're working and trying with. For instance I imagine that your ids might be different (as when conforming with XML ID data type, simple numbers aren't valid as ids, they must be XML names.)

So something more like:

<tag id="id12">
  <name>
    <de-DE>CC BY-SA</de-DE>
  </name>
</tag>

and in that case, the id cannot be converted to number 12 anymore, and it can only be tested for equality with a string, which is 'id12'.

So the correct expression would be:

<xsl:value-of select="/tags/tag[@id='id12']/name/de-DE"/>

Upvotes: 1

Related Questions