2017-05-04 4 views
0

2番目のxmlファイルからサブノード「dateEta」の値を更新したいとします。 「識別」は両方のファイルに共通しています。2番目のxmlファイルを使用してサブノード値を更新する

1.xml

<defac> 
<fac> 
    <identification>170610001-01</identification> 
    <order> 
    <test1>test</test1> 
    <dateEta>2017-02-03</dateEta> 
    <test2>test</test2> 
    </order> 
</fac> 
<fac> 
    <identification >170610002-01</identification> 
    <order> 
    <test1>test</test1> 
    <dateEta>2017-02-03</dateEta> 
    <test2>test</test2> 
    </order> 
</fac> 
<fac> 
    <identification>170610003-01</identification> 
    <order> 
    <test1>test</test1> 
    <dateEta>2017-02-03</dateEta> 
    <test2>test</test2> 
    </order> 
</fac> 
</defac> 

2.xml

<defac> 
<fac> 
    <identification>170610001-01</identification> 
    <order> 
    <dateEta>2017-02-05</dateEta> 
    </order> 
</fac> 
<fac> 
    <identification >170610002-01</identification> 
    <order> 
    <dateEta>2017-01-09</dateEta> 
    </order> 
</fac> 
<fac> 
    <identification>170610003-01</identification> 
    <order> 
    <dateEta>2017-02-08</dateEta> 
    </order> 
</fac> 
</defac> 

私が何をしたい - >私が試した何update.xmlを

<defac> 
    <fac> 
     <identification>170610001-01</identification> 
     <order> 
     <test1>test</test1> 
     <dateEta>2017-02-05</dateEta> 
     <test2>test</test2> 
     </order> 
    </fac> 
    <fac> 
     <identification >170610002-01</identification> 
     <order> 
     <test1>test</test1> 
     <dateEta>2017-01-09</dateEta> 
     <test2>test</test2> 
     </order> 
    </fac> 
    <fac> 
     <identification>170610003-01</identification> 
     <order> 
     <test1>test</test1> 
     <dateEta>2017-02-08</dateEta> 
     <test2>test</test2> 
     </order> 
    </fac> 
    </defac> 

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0"> 

    <xsl:param name="data-uri" select="'2.xml'"/> 
    <xsl:param name="data-doc" select="document($data-uri)"/> 

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

    <xsl:template match="dateEta"> 
     <xsl:copy> 
      <xsl:variable name="match" select="$data-doc//fac[identification = current()/../identification]/order/dateEta"/> 
      <xsl:choose> 
       <xsl:when test="$match"> 
        <xsl:value-of select="$match"/> 
       </xsl:when> 
       <xsl:otherwise> 
        <xsl:value-of select="."/> 
       </xsl:otherwise> 
      </xsl:choose> 
     </xsl:copy>  
    </xsl:template> 
</xsl:stylesheet> 

しかし、それは動作していません。日付は全く更新されません。「dateEta」が「身分証明書」と同じレベルにある場合は動作させることができますが、それが低いレベルにある場合は何も起こりません。

どこでエラーが発生したか知っていますか?

<xsl:variable name="match" select="$data-doc//fac[identification = current()/../../identification]/order/dateEta"/> 

かに:

<xsl:variable name="match" select="$data-doc//fac[identification = current()/../identification]/order/dateEta"/> 

へ:の兄弟ではありません

<xsl:variable name="match" select="$data-doc//fac[identification = current()/ancestor::fac/identification]/order/dateEta"/> 

dateEtaので

は、変更する必要が

答えて

2

ありがとう;その親のorderです。

+0

ありがとうございます!今それは働いている;) – Rflow