CDATA showing up at end of output files

Discussion in 'XML' started by Isaac Councill, Jul 21, 2003.

  1. Hello,

    This seems like a newbie question, but I couldn't find the answer on
    google.
    I've been using xsl to transform rdf files into runnable
    programs in another (non-markup) language. It's been great except for a
    minor hiccup - all text within CDATA blocks shows up at the end of my
    output files without being invited.
    I think I've boiled it down to a specific problem, but I'd like to better
    understand why it is a problem at all.

    I'm using xalan 2.5.1 on Linux with java 1.4.0.

    Here is a sample rdf file for the demonstration:

    <?xml version='1.0' encoding='ISO-8859-1'?> <!DOCTYPE rdf:RDF [
    <!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'> <!ENTITY
    rdfs 'http://www.w3.org/TR/1999/PR-rdf-schema-19990303#'>
    ]>
    <rdf:RDF xmlns:rdf="&rdf;"
    xmlns:rdfs="&rdfs;">
    <test>
    <problematic-string xml:space='preserve'><![CDATA[My cdata block]]>
    </problematic-string>
    </test>
    </rdf:RDF>


    Now here are two simple scripts - one that works as I would expect and one
    that doesn't.

    Good script:

    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rdfs="http://www.w3.org/TR/1999/PR-rdf-schema-19990303#"
    version="1.0">

    <xsl:eek:utput method="text" indent="no"/> <xsl:strip-space elements="*"/>

    <xsl:template match="test">
    <xsl:text>Here is where I want the text: </xsl:text>
    <xsl:call-template name="test"/>
    </xsl:template>

    <xsl:template name="test">
    <xsl:for-each select="problematic-string">
    <xsl:value-of select="."/>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

    This one produces an output file that contains the line: 'Here is where I
    want the text: My cdata block'

    Now for the bad script (with only one small difference):

    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rdfs="http://www.w3.org/TR/1999/PR-rdf-schema-19990303#"
    version="1.0">

    <xsl:eek:utput method="text" indent="no"/> <xsl:strip-space elements="*"/>

    <xsl:template match="bad-test"> <!-- ***The only difference -->
    <xsl:text>Here is where I want the text: </xsl:text>
    <xsl:call-template name="test"/>
    </xsl:template>

    <xsl:template name="test">
    <xsl:for-each select="problematic-string">
    <xsl:value-of select="."/>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>


    This one produces the following output: 'My cdata block'


    Now my question is: why does the second script produce any output at all?
    Do I have to explicitly match every node with CDATA even if I have no use
    for them?

    Thanks for your time,
    Isaac
    Isaac Councill, Jul 21, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Davison
    Replies:
    1
    Views:
    568
    Hal Rosser
    Jul 7, 2004
  2. Dimitre Novatchev

    .CDATA showing up at end of output files

    Dimitre Novatchev, Jul 21, 2003, in forum: XML
    Replies:
    0
    Views:
    1,182
    Dimitre Novatchev
    Jul 21, 2003
  3. Replies:
    3
    Views:
    736
    Joe Kesselman
    Mar 6, 2006
  4. werD
    Replies:
    4
    Views:
    13,494
  5. Spacen Jasset

    line end handling in CDATA section

    Spacen Jasset, Jan 29, 2007, in forum: XML
    Replies:
    2
    Views:
    437
    Richard Tobin
    Jan 29, 2007
Loading...

Share This Page