identity transformation not following -snone?

Here should go questions about transforming XML with XSLT and FOP.
velda
Posts: 21
Joined: Fri Jul 18, 2008 9:48 pm

identity transformation not following -snone?

Post by velda »

Using the standard Identity Transformation, I seem to be having troubles with whitespaces and line breaks. Namely, all my prolog ends up on the first line along with the root element, and all of my formatting whitespaces and line returns are gone.

I am running oX 10 with Saxon-SA 9.1.0.3 and set the -snone option, but it still seems to be stripping whitespaces.
iulian_velea
Posts: 63
Joined: Fri Dec 12, 2003 6:34 pm
Contact:

Re: identity transformation not following -snone?

Post by iulian_velea »

Hello,

I cannot reproduce the problem using a standard identity transformation.
Can you please send us a small XML sample and the stylesheet you are using so we can test your situation.
Another information that may be useful is the Oxygen build number which can be found in the About dialog.

Regards,
Iulian
velda
Posts: 21
Joined: Fri Jul 18, 2008 9:48 pm

Re: identity transformation not following -snone?

Post by velda »

given the following example xml:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<?oxygen SCHSchema="../!schemas/control[0.5].sch" ?>
<control format="0.5" type="moving_head" name="Big Boy" short_name="BBoy" option="Standard" photometrics="bigboy_photo.VPhoto"
mod_date="2008-12-01T15:23:13-06:00" status="du">
<example />
</control>
and the following xslt:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:preserve-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>

<xsl:template match="@mod_date">
<xsl:attribute name="mod_date">
<xsl:value-of select="current-dateTime()" />
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
gives the following output:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?><?oxygen SCHSchema="../!schemas/control[0.5].sch" ?><control format="0.5" type="moving_head" name="Big Boy" short_name="BBoy" option="Standard" photometrics="bigboy_photo.VPhoto" mod_date="2008-12-17T08:37:53.164-06:00" status="du">
<example/>
</control>
Notice the entire prolog is on the same line as the root element, the non-significant carriage return before mod_date is removed, and the space before the closing slash in <example /> is removed.
iulian_velea
Posts: 63
Joined: Fri Dec 12, 2003 6:34 pm
Contact:

Re: identity transformation not following -snone?

Post by iulian_velea »

I used your samples in a transformation and obtained the same output.
Running the following command from a shell gives the same result also:

Code: Select all

java -cp "saxon9sa.jar" net.sf.saxon.Transform -strip:none -s:test.xml -xsl:test.xsl
So the issue is related to the Saxon transformer and maybe the parser used by Saxon is responsible for removing the whitespaces you refer to.
I believe that the "Strip whitespaces" option affects only the whitespace text nodes processing. The whitespaces before the root element and between the attributes are not part of such text nodes and therefore removed.

Best wishes,
Iulian
velda
Posts: 21
Joined: Fri Jul 18, 2008 9:48 pm

Re: identity transformation not following -snone?

Post by velda »

After a little more research I found this site http://www.xmlplease.com/identity-template by Jesper Tverskov which explains the limitations in the xslt 2.0 identity transformation and offers an alternative template that solves the prolog issue, but unfortunately not the insignificant whitespaces and line breaks.

This stylesheet is quite large and does way more than id ever need it to. In addition, it does not work when input and output are both ${currentFileURL}, giving a "Cannot write to a URI that has already been read:" error.

Instead, ive simply given up on retaining the insignificant whitespaces and added the following the cope with the prolog:

Code: Select all


	<xsl:template match="/">
<xsl:text>&#xA;</xsl:text>
<xsl:apply-templates/>
</xsl:template>
as well as manually handling the PIs.
Post Reply