I am trying to use a variable that has xpath in for-each. But it is giving me an error that Expression must evalua开发者_Python百科te to a node-set.
NodeName is defined as
<xsl:variable name="NodeName" select="name(.)"/>
<xsl:variable name="SyncPath"
select="concat('/combinedxml/com.csc_PolicySyncRs/',$NodeName)"/>
and here is for-each loop
<xsl:for-each select="$SyncPath/*">
I will take wild guess and assume you're interested in converting variable to node set in order to use it later in XPath. This could be done using extension function exsl:node-set()
. The documentation have examples of usage.
Quote:
This use case shows the result of using exsl:node-set() to convert a result tree fragment to a node-set.
source
<doc>
<one />
<two />
<three />
<four />
</doc>
stylesheet
<!-- Test exslt:node-set applied to a result tree fragment -->
<xsl:variable name="tree">
<a>
<b>
<c>
<d />
</c>
</b>
</a>
</xsl:variable>
<xsl:template match="/">
<out>
<xsl:value-of select="count(exslt:node-set(//*))" />
</out>
</xsl:template>
result
<out xmlns:exslt="http://exslt.org/common">5</out>
Use:
<xsl:variable name="SyncPath"
select="/combinedxml/com.csc_PolicySyncRs/*[name()=$NodeName]"/>
XSLT 1.0 (and indeed 2.0) has no standard facility for constructing an XPath expression as a string and then evaluating it. Many processors have an extension function to do this, variously called dyn:evaluate, saxon:evaluate, etc.
精彩评论