I have been using Oxygen XML editor for my XSL transformations (Saxon-HE 9.8.0.8 on XSL v. 2 stylesheets) and the indentation of the source and result document have been the same: which is what I need.
When I run XSLT from command line (Saxon-HE 9.8.011J, Java version 1.8.0_161) I do not get the same result (the result document will have no indentation at all). Is there anything I can do to change this?
(<xsl:output indent="yes"/>
would also indent my inline elements which is not what I need, <xsl:strip-space elements/>
would delete some of the spaces between inline elements that are necessary).
Source:
<chapter id="ch3">
<title>Sed quam, quaes apiducius nit peror asperch icatiat</title>
<section id="s1">
<title>Et faccae sitiaessum res re dolorer errovitam,</title>
<paragraph id="p6">
<text>lorerit ab is arum dolore quaepudit exped magnate mpelestinus volupta</text>
</paragraph>
<paragraph id="p7">
<text>lorerit ab is arum <span class="s1">dolore</span> <span class="s2">quaepudit</span> exped magnate mpelestinus volupta</text>
</paragraph>
<paragraph id="p12">
<text>lorerit ab is arum dolore quaepudit exped magnate mpelestinus volupta</text>
</paragraph>
</section>
</chapter>
XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0" xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:template match="*">
<xsl:element name="{local-name()}" >
<xsl:for-each select="@*" >
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="paragraph">
<xsl:element name="paragraph">
<xsl:attribute name="id">p<xsl:number count="paragraph" from="chapter" level="any"></xsl:number>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Command line code
java -cp path\saxon9he.jar net.sf.saxon.Transform -t -s:path\source.xml -xsl:path\transformation.xsl -o:path\result.xml
Except the fact that the source code is in a specific DTD. When I remove the DTD mention at the beginning of the source code, the indentation remains the same, otherwise there is no indentation. What is the reason to this and how can I change it?
Thank you! Maria (I am quite a beginner)
If:
(a) you don't strip space from the input document
(b) your stylesheet copies all text nodes including whitespace text nodes to the result tree
(c) you don't indent with serialization
then the indentation of the result should be the same as the source.
If this isn't happening, then we need to see the details of exactly what you are doing. There are so many ways of getting whitespace wrong, it's impossible to know where you've gone wrong without seeing the detail.
(Incidentally you can use something like suppress-indentation="p"
on xsl:output
to get indentation above the paragraph level but not within paragraphs.)