0
我想從第二個xml文件更新子節點「dateEta」的值。 「識別」在兩個文件中都是相同的。使用第二個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」與「識別」處於同一級別,我可以使其工作,但當它處於較低級別時,什麼都不會發生。
你知道我犯了什麼錯誤嗎?
謝謝
謝謝!現在它正在工作;) – Rflow