Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何仅使用xslt创建xml文件(副本)_Xml_Xslt - Fatal编程技术网

如何仅使用xslt创建xml文件(副本)

如何仅使用xslt创建xml文件(副本),xml,xslt,Xml,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>

我想只使用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>

锤子HG2606
32456240
$30.00
这是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>

如果你写了一封信,那就不用写了

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>
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>

如果你写了一封信,那就不用写了

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>
XSLT

您在属性上运行此操作也是因为它会导致错误。到目前为止,您是如何使用XSLT的?如果您想将XSLT 2.0与
xsl:result document
一起使用,那么您需要使用XSLT 2.0处理器,如Saxon 9或XmlPrime或Raptor/Altova,请参见您运行此on属性也是因为它会导致错误那么到目前为止您是如何使用XSLT的?如果要将XSLT2.0与
xsl:result document
一起使用,则需要使用XSLT2.0处理器,如Saxon 9或XmlPrime或Raptor/Altova,请参阅