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
Xml 根据包含文件更改XSLT的节点名称_Xml_Xslt - Fatal编程技术网

Xml 根据包含文件更改XSLT的节点名称

Xml 根据包含文件更改XSLT的节点名称,xml,xslt,Xml,Xslt,嗨,我有一个XSLT文件,需要转换XML文件 示例XSLT <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <Document> <Customer> <Header>

嗨,我有一个XSLT文件,需要转换XML文件

示例XSLT

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <Document>
      <Customer>
        <Header>
          <Message>
            <xsl:value-of select="//Header/Message"/>
          </Message>
       </Header>
     </Customer>
    </Document>
  </xsl:Template>
  <xsl:include href="Inc1.xsl" />
</xsl:stylesheet> 


现在我需要的是根据底部的include文件名将节点名Customer更改为Supplier,还有一件事,我有文档节点的特定属性,这也取决于include文件


谢谢,希望有人能帮助我。

唯一可行的机制是让附带的样式表处理特定的元素名称和属性:类似于这样:

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

    <xsl:template match="/">
        <Document>
            <xsl:call-template name="apply-document-attributes" />
            <xsl:element name="{$customer-element-name}">
                <Header>
                    <Message>
                        <xsl:value-of select="//Header/Message" />
                    </Message>
                </Header>
            </xsl:element>
        </Document>
    </xsl:template>

    <xsl:include href="Inc1.xsl" />

</xsl:stylesheet> 

以及包含的样式表:

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

    <xsl:variable name="customer-element-name" select="'Supplier'"/>

    <xsl:template name="apply-document-attributes">
        <xsl:attribute name="foo">bar</xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

酒吧
或者



“文档节点的特定属性也取决于包含文件。”这是什么意思?请给我们看一个例子。例如,包含文件的文件名为“Customer.xsl”,那么文档标记将具有不同的属性,如xlsni=Customer,如果是“Supplier.xsl”,那么文档将具有xlsni=Supplier,文档标记后的节点也是如此抱歉,我有一个输入错误:)嗨,我还有一个关于这个的后续问题。
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:variable name="customer-element-name" select="'Customer'"/>

    <xsl:template name="apply-document-attributes"/>
</xsl:stylesheet>