2017-02-27 31 views
1

我想創建只使用XSLT的XML文件的副本,一個XML文件(複印件)。如何創建只使用XSLT

這是XML文件:

<?xml version="1.0" encoding="utf-8" ?> 
<?xml-stylesheet href="fichier_xslt_ecrire.xsl" type="text/xsl"?> 
<tool> 
    <field id="prodName"> 
    <value>HAMMER HG2606</value> 
    </field> 
    <field id="prodNo"> 
    <value>32456240</value> 
    </field> 
    <field id="price"> 
    <value>$30.00</value> 
    </field> 
</tool> 

這是XSL文件:

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

<xsl:output method="xml" indent="yes"/> 
    <xsl:template match="@* | node()">  
     <xsl:result-document method="xml" href="Copy_of_product_{@id}-output.xml"> 
     <xsl:copy> 
      <xsl:apply-templates select="@* | node()"/> 
     </xsl:copy> 
     </xsl:result-document> 
    </xsl:template> 
</xsl:stylesheet> 

但問題是,當我在導航打開XML文件,我沒有得到第二(複製)文件。 那麼我該如何運行這個創建?我需要任何運行時間引擎還是什麼? 因爲我想在沒有任何其他工具的情況下複製xml文件。 感謝您的幫助。如果你想

+0

你的屬性也因運行此對此它會導致錯誤 – Rupesh

+0

那麼到目前爲止如何使用XSLT?如果您想將XSLT 2.0與'xsl:result-document'一起使用,那麼您需要使用像Saxon 9或XmlPrime或Raptor/Altova這樣的XSLT 2.0處理器,請參閱http://stackoverflow.com/documentation/xslt/1129/getting -started與 - XSLT/3641 /安裝有或安裝#噸= 201702271143530551908 –

回答

0

只是文件複製到另一個文件比

XSLT

<?xml version="1.0" encoding="utf-8"?> 
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
     <xsl:output method="xml" indent="yes"/> 
     <xsl:template match="/">  
      <xsl:result-document method="xml" href="Copy_of_product_{//@id}-output.xml"> 
       <xsl:copy> 
        <xsl:apply-templates/> 
       </xsl:copy> 
      </xsl:result-document> 
     </xsl:template> 
     <xsl:template match="node()|@*"> 
      <xsl:copy> 
       <xsl:apply-templates select="node()|@*"></xsl:apply-templates> 
      </xsl:copy> 
     </xsl:template> 
    </xsl:stylesheet> 

,如果你寫一個spilitter不是使用

XSLT 

<xsl:template match="field">  
    <xsl:result-document method="xml" href="Copy_of_product_{@id}-output.xml"> 
     <xsl:copy> 
      <xsl:apply-templates select="@* | node()"/> 
     </xsl:copy> 
    </xsl:result-document> 
</xsl:template> 
<xsl:template match="node()|@*"> 
    <xsl:copy> 
     <xsl:apply-templates select="node()|@*"></xsl:apply-templates> 
    </xsl:copy> 
</xsl:template>