xsl-list
[Top] [All Lists]

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

2013-01-15 11:04:05
There are several ways you could fix this problem.

First, you could switch indentation off entirely (indent="no").

Secondly, you could use schema-awareness on the output side (that is, validate the output against a schema). If you do this, Saxon will not add whitespace within an element that has a mixed-content content model. Validation of course needs Saxon-EE.

Thirdly, you could use the suppress-indentation xsl:output parameter. This was introduced as a Saxon extension (saxon:suppress-indentation) and has found its way into the XSLT 3.0 specification. Either way, you will need Saxon-PE or higher.

Note that the fact that the bold element is empty has nothing to do with it; the indentation will occur for any start tag unless it is suppressed.

I assume that you're not complaining about the translation of <bold></bold> to <bold/>?

Michael Kay
Saxonica


On 15/01/2013 14:14, Raymond Lillibridge wrote:
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(_at_)municode(_dot_)com
Municipal Code Corporation | Facebook | Twitter




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--