![](/img/trans.png)
[英]How can I create an XML file that is a list of files in a target directory using only Ant and XSLT?
[英]how can i create an xml file (copy) using only xslt
我想僅使用xslt創建一個xml文件的副本。
這是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文件。 謝謝你的幫助。
如果你只想在另一個文件中復制該文件
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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.