Question

I am using XSLT to generate an .sql file from an .xml input file. I have some problems with the indentation.

The way the stylesheet is formatted (how many line feeds and carriage returns and tabs) directly effects the output file i.e. if I include a few line feeds and CRs in my stylesheet to make it more readable, they are displayed in the output file as well (this would not be that bad if the tabs didn't affect the formatting of the output file as well): It looks like this:

SQLStatement1<CR><LF>
            <CR><LF>
<CR><LF>
  SQLStatement2<CR><LF>
.... (tabs are also outputted)

I use an ant task to create the .sql file. The target looks like this:

<xslt in="input.xml" 
    out="queries.sql"
    style="createQueries.xls">
</xslt>

I am using XSLT 1.0 and cannot use XSLT 2.0. I thought about modifying some output parameters. However it does not have any effect if I change the method attribute to e.g. 'html' (I guess that the method is set to 'text' since the type of the output file(sql) is not known)

Any ideas on how to fix this issue?

Cheers

Was it helpful?

Solution

You would make it much easier on us if you showed a small but complete XML input sample, an XSLT sample, the output you get and the output you want.

If you use xsl:output method="text" and want to control the white space then make sure you use xsl:text to output literal text and xsl:value-of to output computed text. That way you should be able to control the white space exactly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top