2017-02-01 93 views
0

我想保留元素在XML和刪除其他的屬性元素的屬性中刪除元素,在XSLT 1.0,基於屬性值每畝匹配父屬性XSLT 1.0:基於匹配父

我只想保留DONNEES屬性Jurse與父屬性Date匹配。它可以是任何我不能放置='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')]" /> 

謝謝:)

回答

0

您應該使用在你表達的相對路徑來獲得祖先日期

試試這個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> 
+0

非常感謝它的作品! ! – CRT