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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.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
xml树中具有与特定正则表达式模式匹配的标记的更改值_Xml_Xslt_Xslt 1.0 - Fatal编程技术网

xml树中具有与特定正则表达式模式匹配的标记的更改值

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>

我是xsl新手,遇到了一个问题

我有一个类似于:

<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>