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
如何根据标记的值从xml中删除节点_Xml_Xslt_Xslt 2.0 - Fatal编程技术网

如何根据标记的值从xml中删除节点

如何根据标记的值从xml中删除节点,xml,xslt,xslt-2.0,Xml,Xslt,Xslt 2.0,使用xml和xsl,我想解析特定节点和标记的输入xml。如果标记值以“z”开头,那么我想删除该节点。(或在不使用此节点的情况下创建新文件xml文件) 附上了一个示例xml文件以供参考。由于最后一个节点displayname以“z*”开头,我希望最后一个节点应该被删除 “zseafood” 提前谢谢 <?xml version="1.0" encoding="UTF-8" standalone="no"?> <ItemSet xmlns:ns1="urn:/Items/data"

使用xml和xsl,我想解析特定节点和标记的输入xml。如果标记值以“z”开头,那么我想删除该节点。(或在不使用此节点的情况下创建新文件xml文件)

附上了一个示例xml文件以供参考。由于最后一个节点displayname以“z*”开头,我希望最后一个节点应该被删除

“zseafood”

提前谢谢

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ItemSet xmlns:ns1="urn:/Items/data">
   <ns1:ObjectName>com</ns1:ObjectName>
   <ListOfItems>
      <Item>
         <ns1:Name>name1</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>fruits</ns1:DisplayName>
               <ns1:ValidationErrorMsg>120</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
      <Item>
         <ns1:Name>name2</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>vegetables</ns1:DisplayName>
               <ns1:ValidationErrorMsg>24.</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
      <Item>
         <ns1:Name>name3</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>meat</ns1:DisplayName>
               <ns1:ValidationErrorMsg>12.</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
      <Item>
         <ns1:Name>name4</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>zseafood</ns1:DisplayName>
               <ns1:ValidationErrorMsg>12.</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
   </ListOfItems>
</ItemSet>

通用域名格式
名称1
果实
120
姓名2
蔬菜
24
名字3
肉
12
名字4
zseafood
12

此转换(覆盖):


应用于提供的XML文档时

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ns1="urn:/Items/data">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>

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

 <xsl:template match="Item[.//ns1:DisplayName[starts-with(., 'z')]]"/>
</xsl:stylesheet>
<ItemSet xmlns:ns1="urn:/Items/data">
    <ns1:ObjectName>com</ns1:ObjectName>
    <ListOfItems>
        <Item>
            <ns1:Name>name1</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>fruits</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>120</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
        <Item>
            <ns1:Name>name2</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>vegetables</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>24.</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
        <Item>
            <ns1:Name>name3</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>meat</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>12.</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
        <Item>
            <ns1:Name>name4</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>zseafood</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>12.</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
    </ListOfItems>
</ItemSet>
<ItemSet xmlns:ns1="urn:/Items/data">
   <ns1:ObjectName>com</ns1:ObjectName>
   <ListOfItems>
      <Item>
         <ns1:Name>name1</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>fruits</ns1:DisplayName>
               <ns1:ValidationErrorMsg>120</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
      <Item>
         <ns1:Name>name2</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>vegetables</ns1:DisplayName>
               <ns1:ValidationErrorMsg>24.</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
      <Item>
         <ns1:Name>name3</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>meat</ns1:DisplayName>
               <ns1:ValidationErrorMsg>12.</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
   </ListOfItems>
</ItemSet>

通用域名格式
名称1
果实
120
姓名2
蔬菜
24
名字3
肉
12
名字4
zseafood
12
生成所需的正确结果

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ns1="urn:/Items/data">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>

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

 <xsl:template match="Item[.//ns1:DisplayName[starts-with(., 'z')]]"/>
</xsl:stylesheet>
<ItemSet xmlns:ns1="urn:/Items/data">
    <ns1:ObjectName>com</ns1:ObjectName>
    <ListOfItems>
        <Item>
            <ns1:Name>name1</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>fruits</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>120</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
        <Item>
            <ns1:Name>name2</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>vegetables</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>24.</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
        <Item>
            <ns1:Name>name3</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>meat</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>12.</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
        <Item>
            <ns1:Name>name4</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>zseafood</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>12.</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
    </ListOfItems>
</ItemSet>
<ItemSet xmlns:ns1="urn:/Items/data">
   <ns1:ObjectName>com</ns1:ObjectName>
   <ListOfItems>
      <Item>
         <ns1:Name>name1</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>fruits</ns1:DisplayName>
               <ns1:ValidationErrorMsg>120</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
      <Item>
         <ns1:Name>name2</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>vegetables</ns1:DisplayName>
               <ns1:ValidationErrorMsg>24.</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
      <Item>
         <ns1:Name>name3</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>meat</ns1:DisplayName>
               <ns1:ValidationErrorMsg>12.</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
   </ListOfItems>
</ItemSet>

通用域名格式
名称1
果实
120
姓名2
蔬菜
24
名字3
肉
12

此转换(覆盖):


应用于提供的XML文档时

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ns1="urn:/Items/data">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>

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

 <xsl:template match="Item[.//ns1:DisplayName[starts-with(., 'z')]]"/>
</xsl:stylesheet>
<ItemSet xmlns:ns1="urn:/Items/data">
    <ns1:ObjectName>com</ns1:ObjectName>
    <ListOfItems>
        <Item>
            <ns1:Name>name1</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>fruits</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>120</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
        <Item>
            <ns1:Name>name2</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>vegetables</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>24.</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
        <Item>
            <ns1:Name>name3</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>meat</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>12.</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
        <Item>
            <ns1:Name>name4</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>zseafood</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>12.</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
    </ListOfItems>
</ItemSet>
<ItemSet xmlns:ns1="urn:/Items/data">
   <ns1:ObjectName>com</ns1:ObjectName>
   <ListOfItems>
      <Item>
         <ns1:Name>name1</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>fruits</ns1:DisplayName>
               <ns1:ValidationErrorMsg>120</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
      <Item>
         <ns1:Name>name2</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>vegetables</ns1:DisplayName>
               <ns1:ValidationErrorMsg>24.</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
      <Item>
         <ns1:Name>name3</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>meat</ns1:DisplayName>
               <ns1:ValidationErrorMsg>12.</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
   </ListOfItems>
</ItemSet>

通用域名格式
名称1
果实
120
姓名2
蔬菜
24
名字3
肉
12
名字4
zseafood
12
生成所需的正确结果

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ns1="urn:/Items/data">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>

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

 <xsl:template match="Item[.//ns1:DisplayName[starts-with(., 'z')]]"/>
</xsl:stylesheet>
<ItemSet xmlns:ns1="urn:/Items/data">
    <ns1:ObjectName>com</ns1:ObjectName>
    <ListOfItems>
        <Item>
            <ns1:Name>name1</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>fruits</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>120</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
        <Item>
            <ns1:Name>name2</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>vegetables</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>24.</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
        <Item>
            <ns1:Name>name3</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>meat</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>12.</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
        <Item>
            <ns1:Name>name4</ns1:Name>
            <ns1:ListOfItemDesc>
                <ItemTranslation>
                    <ns1:DisplayName>zseafood</ns1:DisplayName>
                    <ns1:ValidationErrorMsg>12.</ns1:ValidationErrorMsg>
                </ItemTranslation>
            </ns1:ListOfItemDesc>
        </Item>
    </ListOfItems>
</ItemSet>
<ItemSet xmlns:ns1="urn:/Items/data">
   <ns1:ObjectName>com</ns1:ObjectName>
   <ListOfItems>
      <Item>
         <ns1:Name>name1</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>fruits</ns1:DisplayName>
               <ns1:ValidationErrorMsg>120</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
      <Item>
         <ns1:Name>name2</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>vegetables</ns1:DisplayName>
               <ns1:ValidationErrorMsg>24.</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
      <Item>
         <ns1:Name>name3</ns1:Name>
         <ns1:ListOfItemDesc>
            <ItemTranslation>
               <ns1:DisplayName>meat</ns1:DisplayName>
               <ns1:ValidationErrorMsg>12.</ns1:ValidationErrorMsg>
            </ItemTranslation>
         </ns1:ListOfItemDesc>
      </Item>
   </ListOfItems>
</ItemSet>

通用域名格式
名称1
果实
120
姓名2
蔬菜
24
名字3
肉
12