2

最初に、「重複ノードの削除が期待どおりに機能しない」と言って申し訳ありませんが、複数のスレッドを参照してある程度の範囲を拡大するのに役立ちましたが、それでも期待した解決策に達していません。

私のケースを簡単に説明すると、次の子孫でサプライヤーと origin_country_id が同じ場合、XitemSup 複合型要素を削除したいと思います。

以下はxsltコードです

<xsl:stylesheet version="1.0" exclude-result-prefixes="xsl xsd ns3"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:ns3="http://xmlns.oracle.com/TSS_to_RMS/RIBXItemProcess/Supplier">
   <xsl:template match="/">
      <ns3:XItemSupDesc>
         <xsl:for-each select="//ns3:XItemSupDesc/ns3:XitemSup">             
            <xsl:if test="not(ns3:supplier=following::ns3:supplier) or not(ns3:origin_country_id=following::ns3:origin_country_id)">
                   <ns3:XitemSup>
                     <ns3:supplier>
                        <xsl:value-of select="./ns3:supplier"/>
                     </ns3:supplier>
                     <ns3:primary_supp_ind>
                        <xsl:value-of select="./ns3:primary_supp_ind"/>
                     </ns3:primary_supp_ind>
                     <ns3:origin_country_id>
                        <xsl:value-of select="./ns3:origin_country_id"/>
                     </ns3:origin_country_id>
                     <ns3:primary_country_ind>
                        <xsl:value-of select="./ns3:primary_country_ind"/>
                     </ns3:primary_country_ind>
                     <ns3:unit_cost>
                        <xsl:value-of select="./ns3:unit_cost"/>
                     </ns3:unit_cost>
                  </ns3:XitemSup>
               </xsl:if>
         </xsl:for-each>
      </ns3:XItemSupDesc>
   </xsl:template>
</xsl:stylesheet>

しかし、xmlの下に適用すると機能しません

<XItemSupDesc xmlns:ns2="http://xmlns.oracle.com/TSS_to_RMS/RIBXItemProcess/Supplier" xmlns="http://xmlns.oracle.com/TSS_to_RMS/RIBXItemProcess/Supplier">
   <ns2:XitemSup>
      <ns2:supplier>101018</ns2:supplier>
      <ns2:primary_supp_ind>N</ns2:primary_supp_ind>
      <ns2:origin_country_id>CA</ns2:origin_country_id>
      <ns2:primary_country_ind>N</ns2:primary_country_ind>
      <ns2:unit_cost>6</ns2:unit_cost>
   </ns2:XitemSup>
   <ns2:XitemSup>
      <ns2:supplier>102825</ns2:supplier>
      <ns2:primary_supp_ind>N</ns2:primary_supp_ind>
      <ns2:origin_country_id>IN</ns2:origin_country_id>
      <ns2:primary_country_ind>N</ns2:primary_country_ind>
      <ns2:unit_cost>13</ns2:unit_cost>
   </ns2:XitemSup>
   <ns2:XitemSup>
      <ns2:supplier>102825</ns2:supplier>
      <ns2:primary_supp_ind>N</ns2:primary_supp_ind>
      <ns2:origin_country_id>IN</ns2:origin_country_id>
      <ns2:primary_country_ind>N</ns2:primary_country_ind>
      <ns2:unit_cost>24</ns2:unit_cost>
   </ns2:XitemSup>
</XItemSupDesc>

XSLTコードのどこが間違っているのか誰かが教えてくれることを願っています。

4

1 に答える 1

1

xsl:for-eachを使用せず、ID変換をオーバーライドすることをお勧めします。

XML入力

<XItemSupDesc xmlns:ns2="http://xmlns.oracle.com/TSS_to_RMS/RIBXItemProcess/Supplier" xmlns="http://xmlns.oracle.com/TSS_to_RMS/RIBXItemProcess/Supplier">
    <ns2:XitemSup>
        <ns2:supplier>101018</ns2:supplier>
        <ns2:primary_supp_ind>N</ns2:primary_supp_ind>
        <ns2:origin_country_id>CA</ns2:origin_country_id>
        <ns2:primary_country_ind>N</ns2:primary_country_ind>
        <ns2:unit_cost>6</ns2:unit_cost>
    </ns2:XitemSup>
    <ns2:XitemSup>
        <ns2:supplier>102825</ns2:supplier>
        <ns2:primary_supp_ind>N</ns2:primary_supp_ind>
        <ns2:origin_country_id>IN</ns2:origin_country_id>
        <ns2:primary_country_ind>N</ns2:primary_country_ind>
        <ns2:unit_cost>13</ns2:unit_cost>
    </ns2:XitemSup>
    <ns2:XitemSup>
        <ns2:supplier>102825</ns2:supplier>
        <ns2:primary_supp_ind>N</ns2:primary_supp_ind>
        <ns2:origin_country_id>IN</ns2:origin_country_id>
        <ns2:primary_country_ind>N</ns2:primary_country_ind>
        <ns2:unit_cost>24</ns2:unit_cost>
    </ns2:XitemSup>
</XItemSupDesc>

XSLT 1.0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:ns2="http://xmlns.oracle.com/TSS_to_RMS/RIBXItemProcess/Supplier">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

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

    <xsl:template match="ns2:XitemSup">
        <xsl:if test="not(following::ns2:XitemSup[ns2:supplier=current()/ns2:supplier and ns2:origin_country_id=current()/ns2:origin_country_id])">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:if>       
    </xsl:template>

</xsl:stylesheet>

XML出力

<XItemSupDesc xmlns="http://xmlns.oracle.com/TSS_to_RMS/RIBXItemProcess/Supplier" xmlns:ns2="http://xmlns.oracle.com/TSS_to_RMS/RIBXItemProcess/Supplier">
   <ns2:XitemSup>
      <ns2:supplier>101018</ns2:supplier>
      <ns2:primary_supp_ind>N</ns2:primary_supp_ind>
      <ns2:origin_country_id>CA</ns2:origin_country_id>
      <ns2:primary_country_ind>N</ns2:primary_country_ind>
      <ns2:unit_cost>6</ns2:unit_cost>
   </ns2:XitemSup>
   <ns2:XitemSup>
      <ns2:supplier>102825</ns2:supplier>
      <ns2:primary_supp_ind>N</ns2:primary_supp_ind>
      <ns2:origin_country_id>IN</ns2:origin_country_id>
      <ns2:primary_country_ind>N</ns2:primary_country_ind>
      <ns2:unit_cost>24</ns2:unit_cost>
   </ns2:XitemSup>
</XItemSupDesc>

注:XSLT 2.0を使用できる場合は、を削除してxsl:if、テンプレートを次のように変更できます。

<xsl:template match="ns2:XitemSup[following::ns2:XitemSup[ns2:supplier=current()/ns2:supplier and ns2:origin_country_id=current()/ns2:origin_country_id]]"/>
于 2012-10-20T04:47:57.043 に答える