我有一個XSL文件,用於從多個源轉換/構建XML文件,其中多個元素和屬性需要隨時更新。我想知道這種情況是否應該在帶參數的<call-template/>
塊中起作用。XSL - 使用具有多個源XML文件的調用模板
當我通過作爲參數傳遞的外部文件參考,EXPORT/Top/Shapes/Shape/Material
下的「代碼」屬性不被更新:
<xsl:template match="Shapes">
<xsl:copy>
<xsl:for-each select="document('..\TempReportData\TextXML_Output.xml')/Job/Benchtops/Benchtop">
<xsl:apply-templates select="document('..\DesignMaster\EmptyShapeElement.xml')" />
<xsl:call-template name="updateMaterial">
<xsl:with-param name="mCode" select="./Top_number"/>
</xsl:call-template>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template name="updateMaterial" match="@Code[parent::Material]">
<xsl:param name="mCode"/>
<xsl:attribute name="Code">
<xsl:value-of select="$mCode">
</xsl:attribute>
</xsl:template>
這是期望的結果,其中<Material></Material>
元件內的代碼屬性從更新外部文件:
<?xml version="1.0"?>
<EXPORT>
<Top Id="1" Code="B90512">
<Shapes>
<!--Shape-->
<Shape Id="1" Code="Penisola">
<!--Material-->
<Material Code="TOP(2257)"></Material>
</Shape>
<!--Shape-->
<Shape Id="1" Code="Penisola">
<!--Material-->
<Material Code="TOP(2260)"></Material>
</Shape>
</Shapes>
</Top>
</EXPORT>
XML文件TextXML_Output.xml是:
<?xml version="1.0"?>
<Job>
<Job_Number>B90512</Job_Number>
<Job_Address>2nd Floor/ 28-32 Albert Road VIC 3205</Job_Address>
<Benchtops>
<Benchtop>
<Top_number>TOP(2257)</Top_number>
</Benchtop>
<Benchtop>
<Top_number>TOP(2260)</Top_number>
</Benchtop>
</Benchtops>
</Job>
使用多個模板和文件時,我感到有點迷茫,但在我看來,這應該可以正常工作,但事實並非如此。
哪裏元素'Top_number'?它在'TextXML_Output.xml'中,還是在'EmptyShapeElement.xml'中? –
'Top_number'位於'TextXML_Output.xml'中 – paularmy42
考慮將所有需要的文檔儘可能減少到最小程度,以便讓我們重現它,然後發佈所有這些文檔。我們無法調試您不顯示的代碼,我們需要查看輸入文檔。 –