【发布时间】:2025-12-18 17:45:02
【问题描述】:
在我的 XSLT 脚本中,我正在调用递归模板,并且我想将 xPath 作为参数传递给每次迭代。在每次迭代中,我想将孩子的 xPath(*/) 连接到当前路径(请参阅代码)。所以我使用了 concat() 函数,因为它返回一个字符串,所以我无法使用该路径来打印该路径的内容。
<xsl:copy-of select="$path" /> <!--This requests a xPath, not a string-->
谁能告诉我如何连接两个 xpath 或如何将字符串转换为 xpath。
谢谢。
<xsl:template match="/">
<xsl:call-template name="repeatable" >
<xsl:with-param name="limit" select="10" />
</xsl:call-template>
</xsl:template>
<xsl:template name="repeatable">
<xsl:param name="index" select="1" />
<xsl:param name="limit" select="1" />
<xsl:param name="path" select="@*" />
<xsl:copy-of select="$path" />
<xsl:if test="($limit >= $index)">
<xsl:call-template name="repeatable">
<xsl:with-param name="index" select="$index + 1" />
<xsl:with-param name="path" select="concat('*/', $path)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
【问题讨论】:
-
你能告诉我们这段代码的目的/期望的结果是什么吗?也许有更好的方法来完成你想做的事情。请给我们一个示例输入和输出。