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 我的XSLT模板如下所示: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:tem

我想进行标识XSLT转换,将所有标记从输入XML复制到输出XML

我的XSLT模板如下所示:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

    <xsl:template match="*">
        <xsl:copy>
            <xsl:copy-of select="@*" />
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="relation"/>
</xsl:stylesheet
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>


这是因为您通过使用
xsl:output
元素(及其相应的属性)显式省略了XML声明并缩进了输出

有关详细信息,请参见规范:

您还应该看看
xsl:strip space
如何潜在地改变您的输出

此外,一个更为传统的模型如下所示:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

    <xsl:template match="*">
        <xsl:copy>
            <xsl:copy-of select="@*" />
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="relation"/>
</xsl:stylesheet
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>


如果需要省略注释和处理说明,则可以重写此模板,或者将
node()
更改为
*| text()

AFAIK,因为XML解析器不允许XSLT处理器使用XML声明,所以无法复制该声明

无论如何,您都不希望复制声明,因为您的输出可能使用不同的编码。最好提供您自己的声明,使用
指令控制其内容


还请注意,XML声明是可选的-因此您实际上不应该对当前输出有任何问题。

复制XML声明失败是因为XML声明不是XSLT处理器看到的XDM模型的一部分-这反过来是因为它是关于词法表示的信息,这低于XSLT关注的级别


额外的空白可能是因为您使用了indent=“yes”。

“复制所有标记”-这是否意味着您不需要文本?请提供一个示例输入文件和预期的输出文件。是的,我不想复制文本节点,实际上它们不存在于输入文件中。非常感谢,看起来所有的问题都解决了,除了一个:XSLT转换在文件末尾添加了额外的空行,没有任何东西可以帮助我删除它:/