xslt как добавить пробел в начале будущего xml

У меня есть файл XML, с помощью файла XSLT я хочу выбрать только те отели, в имени которых есть Hilton, все выводится правильно, но <.Hotels> пишется не с новой строки, а после тега <?xml>

Hilton.xml (результат)

<?xml version="1.0" encoding="UTF-8"?><Hotels>
    <Hotel Price="370 USD per night">
        <Name>DoubleTree by Hilton New York Downtown</Name>
        <Address>
            <AddressLine>8 Stone Street, New York, New York, 10004, United States of America</AddressLine>
            <City>New York</City>
            <Country>United States of America</Country>
            <State>New York</State>
        </Address>
    </Hotel>
    <Hotel Price="255 USD per night">
        <Name>Millennium Hilton New York One UN Plaza</Name>
        <Address>
            <AddressLine>One United Nations Plaza, Midtown East, New York City, NY 10017, USA New York United States</AddressLine>
            <City>New York City</City>
            <Country>United States</Country>
            <State>NY</State>
        </Address>
    </Hotel>
    <Hotel Price="345 USD per night">
        <Name>Homewood Suites by Hilton New York/Midtown Manhattan Times Square-South, NY</Name>
        <Address>
            <AddressLine>312 West 37th Street, New York, NY, 10018, United States of America</AddressLine>
            <City>New York</City>
            <Country>United States of America</Country>
            <State>NY</State>
        </Address>
    </Hotel>
    <Hotel Price="264 USD per night">
        <Name>Martinique New York on Broadway, Curio Collection by Hilton</Name>
        <Address>
            <AddressLine>49 West 32nd Street, New York, NY 10001, United States</AddressLine>
            <City>New York</City>
            <Country>United States</Country>
            <State>NY</State>
        </Address>
    </Hotel>
</Hotels>

Hotels.xsl

<?xml version="1.0" encoding="UTF-8" ?>

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

    <xsl:template match="/">
        <Hotels>
            <xsl:apply-templates />
        </Hotels>
    </xsl:template>
    <xsl:template match="Hotels/Hotel">
        <xsl:if test="contains(Name, 'Hilton') and (contains(Address/State, 'New York') or contains(Address/State, 'NY'))">
            <Hotel>
                <xsl:attribute name="Price"><xsl:value-of select="@Price"/></xsl:attribute>
                <Name><xsl:value-of select="Name"/></Name>
                <Address>
                    <xsl:apply-templates select="Address"/>
                </Address>
            </Hotel>
        </xsl:if>
    </xsl:template>
    <xsl:template match="Hotels/Hotel/Address">
        <AddressLine><xsl:value-of select="AddressLine"/></AddressLine>
        <City><xsl:value-of select="City"/></City>
        <Country><xsl:value-of select="Country"/></Country>
        <State><xsl:value-of select="State"/></State>
    </xsl:template>

    <xsl:template match="text()" />
</xsl:stylesheet>

Ответы (1 шт):

Автор решения: Yitzhak Khabinsky

Это особенность Oracle Java. Вам нужно добавить одну дополнительную строку, как показано ниже.

transformer.setOutputProperty("http://www.oracle.com/xml/is-standalone", "yes");

Java

...
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xslt);
// =============================================================================
// https://stackoverflow.com/questions/18249490/since-moving-to-java-1-7-xml-document-element-does-not-indent
transformer.setOutputProperty("http://www.oracle.com/xml/is-standalone", "yes");
// =============================================================================
...
→ Ссылка