If you want specific indentation then you will have to insert the relevant line feeds and spaces yourself:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="beans/bean" />
</xsl:template>
<xsl:template match="bean">
<xsl:result-document href='{translate(normalize-space(./property[@name="name"])," /", "_+")}.xml'
doctype-public="-//SPRING//DTD BEAN//EN"
doctype-system="http://www.springframework.org/dtd/spring-beans.dtd"
omit-xml-declaration="no">
<xsl:text> </xsl:text><!-- newline after the DOCTYPE -->
<beans>
<xsl:text> </xsl:text><!-- newline and four spaces -->
<bean>
<xsl:copy-of select="@*" />
<xsl:attribute name="name">bean0</xsl:attribute>
<xsl:copy-of select="node()" />
</bean>
<xsl:text> </xsl:text><!-- newline between </bean> and </beans> -->
</beans>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
For the renaming:
<bean>
<xsl:copy-of select="@*" />
<xsl:attribute name="name">bean0</xsl:attribute>
<xsl:copy-of select="node()" />
</bean>
first I copy all the attributes (possibly including name
) off the original bean
tag, then create a(nother) name
attribute which will override the one that was copied, then finally copy all the child nodes of the original bean
element (which includes elements, comments and text nodes, so will keep the original indentation).