在 XSLT 转换中保留属性之间的空格

Ale*_*ing 4 xml xslt

我有以下 XML:

<?xml version="1.0"?>
<products>
    <product at1="a"
             at2="b"
             at3="c">
    </product>
</products>
Run Code Online (Sandbox Code Playgroud)

和以下 XSLT:

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

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

</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

理论上,xslt 应该保持输入 xml 不变。但是,我处理后得到的输出是:

<?xml version="1.0"?>
<products>
    <product at1="a" at2="b" at3="c">
    </product>
</products>
Run Code Online (Sandbox Code Playgroud)

有什么办法可以防止变压器重新格式化属性之间的间距。我知道输入和输出 xml 在功能上是等效的,但我想保留每行格式的属性以供人类阅读。如果重要的话,我使用 ubuntu 的 xsltproc 来做这个转换:

xsltproc -o test2.xml test.xslt test.xml
Run Code Online (Sandbox Code Playgroud)

Mad*_*sen 5

不,不是使用标准的 XML/XSLT 工具。

该信息不是 XML 信息集的一部分,并且会在 XML 解析器读取 XML 时丢失。因此,不能保留在输出中。

您将需要使用其他内容修改输出以应用这种格式。