2015-11-20 76 views
0

我有一個xml:如何使用xslt將單個元素添加到xml的末尾?

<found> 
    <name>Crusader</name> 
</found> 

我如何編寫樣式,這將有助於增加一個新元素,這個XML?

我想要的結果文件是這樣的:

<found> 
    <name>Crusader</name> 
    <tel>12345</tel> 
</found> 

以下內容替換整個文檔,我只是想在年底

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:template match="/"> 
    <tel>12345</tel> 
</xsl:template> 

</xsl:stylesheet> 

回答

2

這裏補充一個元素的一種方式;

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

<xsl:template match="/found"> 
    <xsl:copy> 
     <xsl:copy-of select="*"/> 
     <tel>12345</tel> 
    </xsl:copy> 
</xsl:template> 

</xsl:stylesheet> 
+0

這正是我所期待的。謝謝。 – Crusaderpyro

相關問題