l0b0
l0b0

Reputation: 58828

How to indent XML by four spaces with xsltproc?

With <output method="xml" indent="yes" encoding="UTF-8"/> xsltproc produces XML files indented by two spaces. Is it possible to change this to four spaces? Full 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>

Upvotes: 1

Views: 478

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 116993

Now that I have tested this, I can state that it works (on macOS 10.13.6):

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

Note that this reformats the transformation result - so it doesn't matter if the stylesheet indents or not.

Upvotes: 1

Related Questions