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 使用XLST2隧道重命名具有特定值的节点_Xslt - Fatal编程技术网

Xslt 使用XLST2隧道重命名具有特定值的节点

Xslt 使用XLST2隧道重命名具有特定值的节点,xslt,Xslt,我正在尝试重命名节点,这些节点具有特定的值。我想在隧道中使用XSLT2,但我被卡住了,不知道出了什么问题 我有 <root> <node1>xxx</node1> <node2>some other data</node2> .. .. .. </root> xxx 其他一些数据 .. .. .. 我想要的XML <root> <node1x>xxx</node1x> <nod

我正在尝试重命名节点,这些节点具有特定的值。我想在隧道中使用XSLT2,但我被卡住了,不知道出了什么问题

我有

<root>
<node1>xxx</node1>
<node2>some other data</node2>
..
..
..
</root>

xxx
其他一些数据
..
..
..
我想要的XML

<root>
<node1x>xxx</node1x>
<node2>some other data</node2>
..
..
..
</root>

xxx
其他一些数据
..
..
..
我正在使用的XSLT

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>

<xsl:template match="*">
<xsl:param name="suffix" tunnel="yes" select="''" />
<xsl:element name="{name()}{$suffix}" namespace="{namespace-uri()}">
<xsl:apply-templates select="@*|node()" />
</xsl:element>
</xsl:template>

<xsl:template match="root/node1/xxx"><xsl:next-match><xsl:with-param name="suffix" tunnel="yes" select="'x'" /></xsl:next-match></xsl:template>

</xsl:stylesheet>

这行不通,我也不明白为什么不行?有人能帮忙吗

非常感谢, e

解决方案: 这是我在下面用户的帮助下提出的解决方案

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

    <xsl:template match="@*|node()">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
    </xsl:template>

    <xsl:template match="*">
    <xsl:param name="suffix" tunnel="yes" select="''" />
    <xsl:element name="{name()}{$suffix}" namespace="{namespace-uri()}">
    <xsl:apply-templates select="@*|node()" />
    </xsl:element>
    </xsl:template>

    <xsl:template match="root/node1[. = 'xxx']"><xsl:next-match><xsl:with-param name="suffix" tunnel="yes" select="'x'" /></xsl:next-match></xsl:template>

    </xsl:stylesheet>

您需要
match=“root/node1[.='xxx']”而不是
match=“root/node1/xxx”

我不知道为什么您认为需要使用隧道参数和下一个匹配,我认为您可以只编写代码

<xsl:template match="root/node1[. = 'xxx']">
  <xsl:element name="{name()}x" namespace="{namespace-uri()}">
    <xsl:apply-templates select="@* | node()"/>
  </xsl:element>
</xsl:template>


感谢您的回复。基本上你们的解决方案不是我想的,但它帮助我找出了问题所在:D。解决方案在上面。谢谢。你有没有检查上面提供的答案,以及我的解决方案?顺便说一句,我一直在这个网站上确认正确的答案,我不需要任何人提醒我,当我必须确认它-因为我有我的妻子:D今天没有什么不同,但也许只有我的时间框架是一些关心你。