xml - Use a variable in XSLT select -


i trying make named template or function pass in node name , select last level of xpath expression. returns string pass in param. in below example value returned "name"

xslt:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">      <xsl:output indent="yes"></xsl:output>      <xsl:template name="get-prefered">         <xsl:param name="field-name"/>           <xsl:variable name="vcondition" select="name"/>         <xsl:variable name="x" select="sources/source[@type='c']/$field-name"/>         <xsl:value-of select="$x"></xsl:value-of>     </xsl:template>      <xsl:template match="/">         <xsl:call-template name="get-prefered">             <xsl:with-param name="field-name">name</xsl:with-param>         </xsl:call-template>         </xsl:template> </xsl:stylesheet> 

input xml:

<?xml version="1.0" encoding="utf-8"?> <sources>     <source type='c'>         <name>joe</name>         <age>10</age>     </source>     <source type='b'>         <name>mark</name>         <age>20</age>     </source> </sources> 

change

<xsl:variable name="x" select="sources/source[@type='c']/$field-name"/> 

to

<xsl:variable name="x" select="sources/source[@type='c']/*[name()=$field-name]"/> 

it returns:

joe 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -