Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Comment processing fails

Help
Paul
2010-05-24
2012-10-08
  • Paul
    Paul
    2010-05-24

    I am using Saxon 9.1.0.8
    Attempting to process comments within xml fails:
    They appear to be processed before anything else and are a mix of chopped-up,
    lost, and duplicated!

    Running the same files through another processor eg Stylus Studio or
    nxslt2.exe – all processes as expected.

    Any help or suggestions...

    XML File:

    <product-definition name="Bob" title="Bob for Apples">
        <topic title="A">
            <include href="BOB-NZL-PUB-Y.2009-46"><!--Apples are fun for All -->
            </include>
            <include href="BOB-NZL-PUB-Y.1978-50"><!--Bananas are big and yellow -->
            </include>
            <include href="BOB-NZL-PUB-Y.2010-72"><!-- Oranges are kind of Orange -->
            </include>
        </topic>
    </product-definition>
    

    XSLT File:

    <?xml version="1.0" encoding="utf-8"?>
    
    <xsl:stylesheet version="2.0" 
                    xmlns:xsl="[url]http://www.w3.org/1999/XSL/Transform[/url]"
                    exclude-result-prefixes="xsl">
    
        <xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="no" indent="no"/>
    
        <xsl:template match="product-definition">
            <product-definition> 
                <xsl:apply-templates/>      
            </product-definition>
        </xsl:template>
    
        <xsl:template match="topic">
            <node>
                <xsl:attribute name="label">
                    <xsl:value-of select="@title"/>
                </xsl:attribute>
                <xsl:apply-templates/>      
            </node>
        </xsl:template>
    
        <xsl:template match="include">
            <content>
                <xsl:attribute name="ref">
                    <xsl:value-of select="@href"/>
                </xsl:attribute>
                <xsl:apply-templates/>      
            </content>
        </xsl:template>
    
        <xsl:template match="comment()">
            <xsl:copy/>
        </xsl:template>
    
    </xsl:stylesheet>
    

    The Result is:

    <?xml version="1.0" encoding="UTF-8"?><!-- Oranges are kind of Or--><!-- Oranges are kind of Orange--><!-- Oranges are kind of Orange --><product-definition>
        <node label="A">
            <content ref="BOB-NZL-PUB-Y.2009-46">
            </content>
            <content ref="BOB-NZL-PUB-Y.1978-50">
            </content>
            <content ref="BOB-NZL-PUB-Y.2010-72">
            </content>
        </node>
    </product-definition>
    
     
  • Michael Kay
    Michael Kay
    2010-05-24

    This is a duplicate posting, it is answered on the other thread.