2016-08-04 10 views
0

temperatureInformationとtemperatureStatsのブロック内で重複を削除する必要があるサンプルメッセージがあります。XSLTの親エンティティと子エンティティでの重複の削除

サンプルメッセージが

<document> 
<body> 
    <party> 
     <gtin>1000909090</gtin> 
     <pos> 
      <attrGroupMany name="temperatureInformation"> 
       <row> 
        <gtin>1000909090</gtin> 
        <attr name="temperatureCode">STORAGE</attr> 
        <attrQualMany name="temperature"> 
         <value qual="FAH">10</value> 
         <value qual="CC">20</value> 
        </attrQualMany> 
        <attrGroupMany name="temperatureStats"> 
         <row> 
          <attr name="StatsCode">CODE1</attr> 
         </row> 
         <row> 
          <attr name="StatsCode">CODE2</attr> 
         </row> 
        </attrGroupMany> 
       </row> 
       <row> 
        <attr name="temperatureCode">STORAGE</attr> 
        <attrQualMany name="temperature"> 
         <value qual="FAH">10</value> 
         <value qual="CC">20</value> 
        </attrQualMany> 
        <attrGroupMany name="temperatureStats"> 
         <row> 
          <attr name="StatsCode">CODE1</attr> 
         </row> 
         <row> 
          <attr name="StatsCode">CODE3</attr> 
         </row> 
        </attrGroupMany> 
       </row> 
       <row> 
        <attr name="temperatureCode">HANDLING</attr> 
        <attrQualMany name="temperature"> 
         <value qual="FAH">10</value>      
        </attrQualMany> 
        <attrGroupMany name="temperatureStats"> 
         <row> 
          <attr name="StatsCode">CODE5</attr> 
         </row> 
         <row> 
          <attr name="StatsCode">CODE6</attr> 
         </row> 
        </attrGroupMany> 
       </row> 
       <row> 
        <attr name="temperatureCode">HANDLING</attr> 
        <attrGroupMany name="temperatureStats"> 
         <row> 
          <attr name="StatsCode">CODE7</attr> 
         </row> 
         <row> 
          <attr name="StatsCode">CODE8</attr> 
         </row> 
        </attrGroupMany> 
       </row> 
      </attrGroupMany> 
     </pos> 
    </party>  
</body> 
</document> 

である私は、温度情報である親の重複を除去した下記のXSLTを使用しますが、子temperatureStats内重複しています

を削除されません予想される出力は

です使用
<document> 
<body> 
    <party> 
     <gtin>1000909090</gtin> 
     <pos> 
      <attrGroupMany name="temperatureInformation"> 
       <row> 
        <gtin>1000909090</gtin> 
        <attr name="temperatureCode">STORAGE</attr> 
        <attrQualMany name="temperature"> 
         <value qual="FAH">10</value> 
         <value qual="CC">20</value> 
        </attrQualMany> 
        <attrGroupMany name="temperatureStats"> 
         <row> 
          <attr name="StatsCode">CODE1</attr> 
         </row> 
         <row> 
          <attr name="StatsCode">CODE2</attr> 
         </row> 
         <row> 
          <attr name="StatsCode">CODE3</attr> 
         </row> 
        </attrGroupMany> 
       </row> 
       <row> 
        <attr name="temperatureCode">HANDLING</attr> 
        <attrQualMany name="temperature"> 
         <value qual="FAH">10</value>      
        </attrQualMany> 
        <attrGroupMany name="temperatureStats"> 
         <row> 
          <attr name="StatsCode">CODE5</attr> 
         </row> 
         <row> 
          <attr name="StatsCode">CODE6</attr> 
         </row> 
        </attrGroupMany> 
       </row> 
       <row> 
        <attr name="temperatureCode">HANDLING</attr> 
        <attrGroupMany name="temperatureStats"> 
         <row> 
          <attr name="StatsCode">CODE7</attr> 
         </row> 
         <row> 
          <attr name="StatsCode">CODE8</attr> 
         </row> 
        </attrGroupMany> 
       </row> 
      </attrGroupMany> 
     </pos> 
    </party>  
</body> 
</document> 

XSLTは

です

誰かが私が間違っているところで私を導くことはできますか?

+1

このXSLTを試してみてください、私はあなたの入力/出力/ XSLTを分析するために懸命に試みたが、あまり理解できませんでした。問題を説明的に説明することができますか? –

+0

行1と行2で、温度コードと温度の連結値が重複しています。私が言及したXSLTから削除されていますが、重複する(CODE1値が2つある)対応するStatsCodeは削除されません。 XSLTをもう一度更新しました。 – Victor

+0

私は取り外しに使われる方法が信頼できないと感じます。あなたの 'attrQualMany [@name = 'temperature']/value要素が前の要素と同じ順番でないか、それらの要素の1つが欠けている場合、それらは重複と見なされません。 –

答えて

1

重複した "temperatureInformation"要素を削除するだけでなく、そのような別個の要素ごとに、グループ内のすべての要素の個別の "temperatureStats"要素をマージするように見えます。

これはグループの第二のレベルであるように、このための鍵は、あまりにもグループ化の最初のレベルを考慮する必要があるので、このようになります。

<xsl:key name="grouptemperatureStats" 
     match="party/pos/attrGroupMany[@name = 'temperatureInformation']/row/attrGroupMany[@name = 'temperatureStats']/row" 
     use="concat(generate-id(ancestor::pos), '|', ../../../attr[@name = 'temperatureCode'], '|', ../../../attrQualMany[@name = 'temperature'], '|', attr[@name = 'StatsCode'])"/> 

テンプレートマッチングでは、これを使用するには「temperatureStats」要素には、まず、あなたはその後、

番目のキーを使用して、この内の異なる「temperatureStats」の要素を選択することができ、現在の親グループ内のすべての要素

<xsl:variable name="group" 
        select="key('grouptemperatureInformation', concat(generate-id(ancestor::pos), '|', ../attr[@name = 'temperatureCode'], '|', ../attrQualMany[@name = 'temperature']))/attrGroupMany[@name='temperatureStats']/row" /> 

を選択することになります

<xsl:apply-templates select="@* | $group[generate-id() = generate-id(key('grouptemperatureStats', concat(generate-id(ancestor::pos), '|', ../../../attr[@name = 'temperatureCode'], '|', ../../../attrQualMany[@name = 'temperature'], '|', attr[@name = 'StatsCode']))[1])]"/> 

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:key name="grouptemperatureInformation" 
      match="party/pos/attrGroupMany[@name = 'temperatureInformation']/row" 
      use="concat(generate-id(ancestor::pos), '|', attr[@name = 'temperatureCode'], '|', attrQualMany[@name = 'temperature'])"/> 

    <xsl:key name="grouptemperatureStats" 
      match="party/pos/attrGroupMany[@name = 'temperatureInformation']/row/attrGroupMany[@name = 'temperatureStats']/row" 
      use="concat(generate-id(ancestor::pos), '|', ../../../attr[@name = 'temperatureCode'], '|', ../../../attrQualMany[@name = 'temperature'], '|', attr[@name = 'StatsCode'])"/> 

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

    <xsl:template match="attrGroupMany[@name = 'temperatureInformation']"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*"/> 
      <xsl:apply-templates select="row[generate-id() = generate-id(key('grouptemperatureInformation', concat(generate-id(ancestor::pos), '|', attr[@name = 'temperatureCode'], '|', attrQualMany[@name = 'temperature']))[1])]"/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="attrGroupMany[@name = 'temperatureStats']"> 
     <xsl:variable name="group" select="key('grouptemperatureInformation', concat(generate-id(ancestor::pos), '|', ../attr[@name = 'temperatureCode'], '|', ../attrQualMany[@name = 'temperature']))/attrGroupMany[@name='temperatureStats']/row" /> 
     <xsl:copy> 
      <xsl:apply-templates select="@* | $group[generate-id() = generate-id(key('grouptemperatureStats', concat(generate-id(ancestor::pos), '|', ../../../attr[@name = 'temperatureCode'], '|', ../../../attrQualMany[@name = 'temperature'], '|', attr[@name = 'StatsCode']))[1])]"/> 
     </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 
+0

ありがとうございました。 1つの場所で、私が編集して削除した余分な../が使用されました。 – Victor

関連する問題