Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.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 XSLT 1.0:根据匹配父元素属性的元素属性删除元素_Xml_Xslt_Xslt 1.0 - Fatal编程技术网

Xml XSLT 1.0:根据匹配父元素属性的元素属性删除元素

Xml XSLT 1.0:根据匹配父元素属性的元素属性删除元素,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,在XSLT1.0中,我希望基于与父属性匹配的属性值将元素保留在XML中,并删除其他元素 我只想保留属性Journee与父属性日期匹配的DONNEES元素。它可以是任何我不能输入的日期,比如='2015-09-17T06:00:00' 下面是XML示例 <?xml version="1.0"?> <Root> <JOURNEE Date="2015-09-17T06:00:00"> <ID> <D

在XSLT1.0中,我希望基于与父属性匹配的属性值将元素保留在XML中,并删除其他元素

我只想保留属性Journee与父属性日期匹配的DONNEES元素。它可以是任何我不能输入的日期,比如='2015-09-17T06:00:00'

下面是XML示例

<?xml version="1.0"?>
<Root>
    <JOURNEE Date="2015-09-17T06:00:00">
        <ID>
            <DONNEES Journee="2015-09-17T06:00:00"/>
            <DONNEES Journee="2015-09-18T06:00:00"/>
            <DONNEES Journee="2015-09-19T06:00:00"/>
        </ID>
    </JOURNEE>
    <JOURNEE Date="2015-09-18T06:00:00">
        <ID>
            <DONNEES Journee="2015-09-17T06:00:00"/>
            <DONNEES Journee="2015-09-18T06:00:00"/>
            <DONNEES Journee="2015-09-19T06:00:00"/>
        </ID>
    </JOURNEE>
    <JOURNEE Date="2015-09-19T06:00:00">
        <ID>
            <DONNEES Journee="2015-09-17T06:00:00"/>
            <DONNEES Journee="2015-09-18T06:00:00"/>
            <DONNEES Journee="2015-09-19T06:00:00"/>
        </ID>
    </JOURNEE>
</Root>

这是我想要的输出

<Root>
<JOURNEE Date="2015-09-17T06:00:00">
<ID>
<DONNEES Journee="2015-09-17T06:00:00"/>
</ID>
</JOURNEE>
<JOURNEE Date="2015-09-18T06:00:00">
<ID>
<DONNEES Journee="2015-09-18T06:00:00"/>
</ID>
</JOURNEE>
<JOURNEE Date="2015-09-19T06:00:00">
<ID>
<DONNEES Journee="2015-09-19T06:00:00"/>
</ID>
</JOURNEE>
</Root>

这是我目前使用的XSLT,它无法删除所有数据

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

<xsl:template match="/*/*/*DONNEES[(@Journee != /*/JOURNEE/@Date)]" />

我尝试了这个,它的工作,但我不能有这样的数据

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

<xsl:template match="/*/*/*DONNEES[(@Journee != '2015-09-17T06:00:00')]" />


谢谢:)

您应该在表达式中使用相对路径来获取祖先日期

试试这个XSLT

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" />
    <xsl:strip-space elements="*" />

    <xsl:template match="DONNEES[@Journee != ../../@Date]" />

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