I
Isaac Councill
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">
<xslutput 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">
<xslutput 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
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">
<xslutput 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">
<xslutput 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