Home > Blockchain >  XSLT use variable/parameter in XPATH
XSLT use variable/parameter in XPATH

Time:12-27

I am trying to declare a variable/parameter in the beginning of my XSL sheet and use it later to filter on in XPATH:

<xsl:param name="MemberName">Lara</xsl:param>
<!-- other stuff -->
<xsl:for-each select="LIBRARY/MEMBER[MEMBER_NAME = '$MemberName']">
<!-- other stuff -->        

but the resulting output is empty, whereas if I replace '$MemberName' with 'Lara' it works fine.

CodePudding user response:

Your code is looking for a MEMBER whose MEMBER_NAME is the literal string "$MemberName".

To look for a MEMBER whose MEMBER_NAME is equal to the value of the $MemberName param, remove the quotes surrounding the param name:

<xsl:for-each select="LIBRARY/MEMBER[MEMBER_NAME = $MemberName]">
  • Related