0

I am quite new to XSL and I would like to use my variable $language inside my XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="data">

    <xsl:value-of select="concat(//text-, $language)"/> 

  </xsl:template>

</xsl:stylesheet>

How can this be done?

This is my XML:

<data>
  <params>
    <language>en</language>
  </params>

  <static>
    <entry id="1">
        <text-en>Hello</text-en>
    </entry>
    <entry id="2">
        <text-fr>Boujour</text-fr>
    </entry>
  </static>
</data>

Thanks for any help!

Tintin81
  • 9,821
  • 20
  • 85
  • 178

1 Answers1

4

You should change the structure of the input XML and use e.g. <text xml:lang="en">Hello</text> if you can, then you can write <xsl:value-of select="//text[lang($language)]"/>.

If you can't change the structure of the input XML, use <xsl:value-of select="//*[local-name() = concat('text-', $language)]"/>.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • Excellent, thanks a lot! I went with the second version because unfortunately I can't change my XML in this case. – Tintin81 Sep 08 '13 at 11:53