I have an XML document of the following kind:
<item>
<item>
<item>
... (same elements <item> ... </item> here)
</item>
</item>
</item>
… and the following XSL-transform:
<xsl:template match="item"><xsl:text>
open</xsl:text>
<xsl:apply-templates/><xsl:text>
close</xsl:text>
</xsl:template>
What I obtain is:
open
open
open
close
close
close
So I wonder whether it is possible to somehow get an output with indents like this:
open
open
open
close
close
close
Thanks for your help!
P.S. It should be definitely possible to obtain what I want to by letting output method of the transformation to be HTML. However, I need to make indents “directly” in the text, not using any kind of HTML’s lists etc.
This transformation:
when applied on the provided XML document:
produces the wanted, indented output:
Explanation:
The
$pIndentparameter is used to hold the string of whitespace to be prepended to the non-white space output. Whenever anxsl:apply-templatesis used, the value passed with this parameter is expanded by two spaces.