Resolve XPaths sent as parameters

I’m trying to resolve a parameter into a valid XPath, so that I can use xsl:for-each with it. Here is the code:

<xsl:call-template name=“PrintQuoteCompGridRow”>
<xsl:with-param name=“Heading”>Quote Ref.:</xsl:with-param>
<xsl:with-param name=“XPath”>/Message/Body/Risk[@Type=‘Quote’]</xsl:with-param>
<xsl:with-param name=“Field”>@QuoteSeqNo</xsl:with-param>
</xsl:call-template>


<xsl:template name=“PrintQuoteCompGridRow”>
<xsl:param name=“Heading”/>
<xsl:param name=“XPath” select=“null”/>
<xsl:param name=“Field”/>



<xsl:value-of select="$Heading"/>



<xsl:for-each select=“ms:node-set($XPath)”>


<xsl:value-of select=“ms:node-set($Field)”/>



</xsl:for-each>

</xsl:template>

However, the output doesn’t loop through the $XPath sent (which is a valid XPath).

Any ideas as to how I can resolve this?

Robin

Hello there,

Resolving an XPath expression from a variable/parameter is possible using the extension function evaluate().

Depending on your XSLT engine you may choose the right option :

. MSXML :

There is no standard to perform such thing, you need to use an extension code. Please refer to
this page.

. Xalan (and maybe Saxon) :

Use EXSLT function evaluate(). See this page.

Hope this help.

Bertrand Martel
Software AG France