How to eval an XSL constructed XPath expression

2019-05-10 22:16发布

Humm...

<xsl:value-of select="$document/@*[name() eq $attrName]"/>

seems to be the solution... Regards, Christophe

I have a variable that contains the name of an attribute to query. How can I wrote such an XPath expression ? Here is an example of what I would like to do

<xsl:variable name="attrName" select="$config//conf:document[@id=$docId]/@archive-ventil-attr"/>
<xsl:value-of select="$document/@{$attrName}"/>

I use XSLT 2.0

Thanks a lot in advance, Christophe

标签: xslt xslt-2.0
1条回答
Melony?
2楼-- · 2019-05-10 22:52

With a complete XPath expression you would need an evaluate function which is in XSLT 1.0 and 2.0 only available as an extension, see http://www.saxonica.com/documentation/extensions/functions/evaluate.xml (which also suggests XSLT 3.0 gets an xsl:evaluate instruction).

As long as you simply have a string with a local name it should suffice to use <xsl:value-of select="$elements/@*[local-name() = $attrName]"/>. This assumes $elements is a node-set (XPath 1.0) or sequence (XPath 2.0) of element nodes.

查看更多
登录 后发表回答