如何将 xpath 存储在变量中并将其与 XSLT 1.0 一起使用
我正在尝试使用 for-each 中具有 xpath 的变量。但这给了我一个错误,即表达式必须计算为节点集。
NodeName 定义为
<xsl:variable name="NodeName" select="name(.)"/>
<xsl:variable name="SyncPath"
select="concat('/combinedxml/com.csc_PolicySyncRs/',$NodeName)"/>
,这里是 for-each 循环
<xsl:for-each select="$SyncPath/*">
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/*">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将进行大胆猜测并假设您有兴趣将变量转换为节点集以便稍后在 XPath 中使用它。这可以使用扩展函数
exsl:node-set()
来完成。 文档有使用示例。引用:
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:
使用:
Use:
XSLT 1.0(实际上是 2.0)没有用于将 XPath 表达式构造为字符串然后对其求值的标准工具。许多处理器都有一个扩展函数来执行此操作,分别称为 dyn:evaluate、saxon:evaluate 等。
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.