XSL : Access a XML node dynamically

2013-05-15
Laurent Bientz

If you want to dynamically access a dynamically XML node.

<!--
  - Select a XML node with dynamic node name (xPATH)  -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">
  <xsl:template match="root">
    <xsl:variable name="dynamicNode" select="'user_name'" />

    <!-- xPath: "//View/user/user_name" -->
    <xsl:value-of select="//View/user/*[name()=$dynamicNode]" />

  </xsl:template>
</xsl:stylesheet>

 

Comment

USER EXPERIENCE

Wandi invites you to discover a new approach to navigating a website...
Are you ready?

Launch the experience