0

I am trying to use a variable that has xpath in for-each. But it is giving me an error that Expression must evaluate 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/*">

6

3 Answers 3

2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

exslt is undefined even after adding the namespace.
1

Use:

<xsl:variable name="SyncPath"
    select="/combinedxml/com.csc_PolicySyncRs/*[name()=$NodeName]"/>

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.