[英]how can i create an xml file (copy) using only xslt
I would like to create a copy of an xml file using only xslt. 我想仅使用xslt创建一个xml文件的副本。
this is the xml file : 这是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>
this is the xsl file: 这是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>
But the problem is, when i open the xml file in a navigator, i dont get the second (the copy) file created. 但问题是,当我在导航器中打开xml文件时,我没有创建第二个(副本)文件。 So how can i run this creation ?
那我怎么能运行这个创作呢? do i need any runtime engin or something ?
我需要任何运行时引擎或什么? Because i want to copy the xml file without any other tools.
因为我想在没有任何其他工具的情况下复制xml文件。 Thanks for your help.
谢谢你的帮助。
if you want just copy that file in another document than 如果你只想在另一个文件中复制该文件
XSLT 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>
and if you write a spilitter than use 如果你写一个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.