1

With<output method="xml" indent="yes" encoding="UTF-8"/> xsltproc生成由两个空格缩进的 XML 文件。是否可以将其更改为四个空格?完整的 XSLT

<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
    <output method="xml" indent="yes" encoding="UTF-8"/>
    <strip-space elements="*"/>

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

    <template match="*">
        <copy>
            <apply-templates select="@*"/>
            <apply-templates>
                <sort select="name()"/>
                <sort select="@*[1]"/>
                <sort select="@*[2]"/>
                <sort select="@*[3]"/>
                <sort select="@*[4]"/>
                <sort select="@*[5]"/>
                <sort select="@*[6]"/>
            </apply-templates>
        </copy>
    </template>
</stylesheet>
4

1 回答 1

1

现在我已经对此进行了测试,我可以声明它可以工作(在 macOS 10.13.6 上):

xsltproc '/path/to/stylesheet.xsl' '/path/to/input.xml' | tidy -i -xml --indent-spaces 4

请注意,这会重新格式化转换结果 - 因此样式表是否缩进并不重要。

于 2021-11-14T20:03:38.787 回答