Reputation: 6833
I am doing a very simple xslt for a source node like:
<p>
<media type="photo" id="lr002662" rights="licensed">
<title>Logging in Canada</title>
</media>Logging is cutting down trees for <definition>
<word-term>lumber</word-term>
<word-definition>wood</word-definition>
</definition>. Loggers are also called <i>lumberjacks.</i>
</p>
I am running this source node on my xslt stylesheet, once in xmlspy, I got the following output:
<para>
<media type="photo" source="lr002662" rights="licensed">
<resource.title>Logging in Canada</resource.title>
</media>Logging is cutting down trees for <italic>lumber</italic> (wood). Loggers are also called <italic>lumberjacks.</italic>
</para>
But then I run this in command line with saxon9he.jar file using the same xslt stylesheet, I got the following:
<para>
<media type="photo" source="lr002662" rights="licensed">
<resource.title>Logging in Canada</resource.title>
</media>Logging is cutting down trees for
<italic>lumber</italic>
(wood)
. Loggers are also called <italic>lumberjacks.</italic>
</para>
As you can see, the text after the media tag now contains so many carriage returns in it, and that is not what I want. I've been using the XMLSpy so never noticed this problem. Could any experts suggest a way to debug or provide my xslt?
Upvotes: 1
Views: 272
Reputation: 66714
The differences are due to the manner in which the Altova XML processor handles whitespace in mixed content.
Whitespace in XML document
By default, the Altova XSLT 2.0 Engine strips all boundary whitespace from boundary-whitespace-only nodes in the source XML document. The removal of this whitespace affects the values that the
fn:position()
,fn:last()
,fn:count()
, andfn:deep-equal()
functions return. For more details, see Whitespace-only Nodes in XML Document in the XPath 2.0 and XQuery 1.0 Functions section.
AltovaXML strips the "boundary-whitespace" text nodes between elements that have whitespace-only content:
A boundary-whitespace-only text node is a child whitespace-only text node that occurs between two elements within an element of mixed content.
As lwburk suggested in his answer, you can instruct other processors to do the same by adding the following to your stylesheet:
<xsl:strip-space elements="*"/>
However, you cannot get AltovaXML to preserve the spaces because they have not implemented xsl:preserve-space
or xsl:strip-space
and will always strip them out.
Upvotes: 3
Reputation: 60414
The line breaks are there in the source, so I'd expect them to appear in the transformation's output, unless they were specifically removed. You can strip all white-space-only text nodes using:
<xsl:strip-space elements="*"/>
This should be at the top level of your stylesheet (as a child of the root xsl:stylesheet
element).
Upvotes: 1