xml树中具有与特定正则表达式模式匹配的标记的更改值
我是xsl新手,遇到了一个问题 我有一个类似于:xml树中具有与特定正则表达式模式匹配的标记的更改值,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,我是xsl新手,遇到了一个问题 我有一个类似于: <abc> <def> <ghi> <hello:abcXYZ>1</hello:abcXYZ> <hello:defXYZ>10</hello:defXYZ> <hello:defXYZ>11</hello:defXYZ>
<abc>
<def>
<ghi>
<hello:abcXYZ>1</hello:abcXYZ>
<hello:defXYZ>10</hello:defXYZ>
<hello:defXYZ>11</hello:defXYZ>
<hello>5<hello>
</ghi>
</def>
</abc>
1.
10
11
5.
我希望在xsl中有一个模板匹配,以便对于树“abc/def/ghi”中的标记,匹配模式“hello*XYZ”(以“hello”开始,以“XYZ”结束),其中的值应替换为零
这样,输出xml将如下所示:
<abc>
<def>
<ghi>
<hello:abcXYZ>0</hello:abcXYZ>
<hello:defXYZ>0</hello:defXYZ>
<hello:defXYZ>0</hello:defXYZ>
<hello>5<hello>
</ghi>
</def>
</abc>
0
0
0
5.
谁能帮忙吗。谢谢。假设XSLT 2.0,将描述转换为正则表达式模式和匹配模式并不困难:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="pattern" select="'hello.*XYZ'"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="abc/def/ghi/*[matches(name(), $pattern)]">
<xsl:copy>0</xsl:copy>
</xsl:template>
</xsl:stylesheet>
0
转变
<abc xmlns:hello="http://example.com/">
<def>
<ghi>
<hello:abcXYZ>1</hello:abcXYZ>
<hello:defXYZ>10</hello:defXYZ>
<hello:defXYZ>11</hello:defXYZ>
<hello>5</hello>
</ghi>
</def>
</abc>
1.
10
11
5.
进入
0
0
0
5.
您已经用XSLT 1.0和2.0标记了您的问题-您实际需要这两个选项中的哪一个?我可以用XSLT 1做任何方式吗?如果您将match=“abc/def/ghi/*[matches(name(),$pattern)]”
更改为match=“abc/def/ghi/*[以(name(),'hello')开头)和子字符串(name(),字符串长度(name())-2)='XYZ“
您有一个模式可以使用XSLT 1.0是的,我会试试。。。谢谢
<abc xmlns:hello="http://example.com/">
<def>
<ghi>
<hello:abcXYZ>0</hello:abcXYZ>
<hello:defXYZ>0</hello:defXYZ>
<hello:defXYZ>0</hello:defXYZ>
<hello>5</hello>
</ghi>
</def>
</abc>