Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在XSLT中连接两个XPath_Xslt_Xpath_Concat - Fatal编程技术网

在XSLT中连接两个XPath

在XSLT中连接两个XPath,xslt,xpath,concat,Xslt,Xpath,Concat,在我的XSLT脚本中,我调用了一个递归模板,并希望将xPath作为参数传递给每个迭代。在每次迭代中,我希望将子级的xPath(*/)连接到当前路径(请参考代码)。所以我使用concat()函数,因为它返回一个字符串,所以我无法使用该路径打印该路径的内容 <xsl:copy-of select="$path" /> <!--This requests a xPath, not a string--> 那么,有谁能告诉我如何连接两个xpath,或者如何将字符串转换为xp

在我的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>


您要做的是动态创建xpath并使用它。这在XSLT3.0中是可能的,要使用的函数是evaluate()。

在我等待您回答我上面的问题时,这里有一个XSLT,它完成了您似乎要做的事情:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text" indent="yes" omit-xml-declaration="yes"/>

  <xsl:template match="@*">
    <xsl:value-of select="concat(name(), ' = ', ., '&#xA;')"/>
  </xsl:template>

  <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="current" select="." />

    <xsl:apply-templates select="$current/@*" />

    <xsl:if test="($limit >= $index)">
      <xsl:call-template name="repeatable">
        <xsl:with-param name="index" select="$index + 1" />
        <xsl:with-param name="limit" select="$limit" />
        <xsl:with-param name="current" select="$current/*" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>

这和你想做的接近吗?如果没有,请澄清。

您能告诉我们此代码的目的/预期结果是什么吗?也许有更好的方法来完成你想做的事情。请给我们一个输入和输出的例子。非常感谢。这正是我想要的。
<root a1="a" a2="b">
  <cont a3="c" a4="d">
    <child a5="e" a6="f" />
  </cont>
  <cont a7="g" a8="h">
    <child a9="i" a10="j">
      <subchild a11="k" a12="l" />
    </child>
  </cont>
</root>
a1 = a
a2 = b
a3 = c
a4 = d
a7 = g
a8 = h
a5 = e
a6 = f
a9 = i
a10 = j
a11 = k
a12 = l