[xsl] Saxon 9.4 <bold></bold> Transformed to (newline)</bold> Problem

Subject: [xsl] Saxon 9.4 <bold></bold> Transformed to (newline)</bold> Problem
From: Raymond Lillibridge <RLillibridge@xxxxxxxxxxxx>
Date: Tue, 15 Jan 2013 14:14:28 +0000
List members,

Due to some batch processing, some of my input XML may have empty elements.

Here is some sample XML:
<level1>
<para> Here is some text inside a para tag. <bold></bold> Note that the 'bold'
element before the word Note is empty.  I would like it to stay that way
without the insertion of a newline.</para> </level1>


When I transform this XML, using Saxon 9.4, the <bold></bold> element is
getting converted similar to the following:
<level1>
<para> Here is some text inside a para tag.
         <bold/> Note that the 'bold' element before the word Note is empty.
I would like it to stay that way.</para> </level1>


The Problem:
Due to further batch processing needs, I do not want the insertion of a
newline before the <bold/> element, which is being created after running an
XSLT transformation on the sample XML above.  (XMLSpy does not insert the
newline, by the way, but I want to use Saxon for my transformation.)  In my
xsl file I do not have an explicit template match for the 'bold' element.

My XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:fo="http://www.w3.org/1999/XSL/Format";
xmlns:mcc="http://www.municode.com/xslt";>

<xsl:strip-space elements="*" />
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<!-- To Get:  {$InputDocPath} -->
<xsl:include href="./MCC_LIB.xsl"/>

<xsl:template match="/">
	<xsl:result-document href="{$InputDocPath}/Book_ALL.xml">
		<xsl:apply-templates select="node()" />
	</xsl:result-document>
</xsl:template>

<xsl:template match="book">
		<xsl:element name="book">
			<xsl:element name="bookinfo">
				<xsl:element name="title"></xsl:element>
				<xsl:element name="subtitle"></xsl:element>
			</xsl:element>
			<xsl:apply-templates select="node()"/>
		</xsl:element>
</xsl:template>


<xsl:template match="level1|level2|level3|level4|level5|level6">
	<xsl:copy-of select="./node()" copy-namespaces="no" /> </xsl:template>


<!-- CATCH-ALL ==================================================== -->
	<xsl:template match="@*|node()">
		<xsl:copy-of select="./node()" copy-namespaces="no" />
	</xsl:template>
</xsl:stylesheet>



Looking in the Saxon documentation, I was not able to find a switch to control
the transformation behavior that changes the <bold></bold> to
(newline)<bold/>.

I'd rather not use XMLSpy since all my other batch transformations are using
Saxon.
If there is a configuration switch for Saxon, could someone direct me where I
may learn about it.

Or, would it be more practical to write a template to remove the "empty"
<bold></bold> element, or better yet, remove all empty elements?  I don't know
how this would be written, and would appreciate any insights someone may
offer.


Kind regards,

Raymond Lillibridge
Sr. Software Engineer
rlillibridge@xxxxxxxxxxxx
Municipal Code Corporation | Facebook | Twitter

Current Thread