473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

CDATA showing up at end of output files

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:output 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:output 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
Jul 20 '05 #1
0 1975

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: John van Terheijden | last post by:
Hi. I'm trying to develop a program that uses XML files store data. I'm using Windows XP, Apache 1.3.29 and PHP 4.3.4. Right now the XML file is read using the xml_parser_create(),...
4
by: alainpoint | last post by:
I am experimenting with ElementTree and i came accross some (apparently) weird behaviour. I would expect a piece of XML to be read, parsed and written back without corruption (except for the...
0
by: Dimitre Novatchev | last post by:
You seem to be unaware of the xslt processing which uses the built-in rules in the absence of templates that match some selected node. http://www.w3.org/TR/xslt#built-in-rule According to the...
1
by: chris | last post by:
Confused somewhat xml newbie. I'm trying to output xml with a CDATA section, using saxutils.XMLGenerator, but the output contains escaped '<' and '>' and '&' from the CDATA element. Shouldn't it...
4
by: troppfigo | last post by:
I have this example of xml <?xml version="1.0"?> <xml> <!]> </xml> I want to extract the contained data from <body> tag using an xslt transformation. I want to obtain this
2
by: Steveino | last post by:
Hello, Just wondering if anyone could shed any light on this, it's probably me just being silly... I have a dataset that I've used to create an XmlDataDocument, in order to apply XSL. The XSL...
1
by: RolfK | last post by:
Hello Experts, I have a small problem with copy of CDATA sections. (I'm using XSLT2.0 ) My output target is defined as txt. In my xml source is a CDATA section to be put as it is into the...
7
by: Silfheed | last post by:
Heyas So first off I know that CDATA is generally hated and just shouldn't be done, but I'm simply required to parse it and spit it back out. Parsing is pretty easy with lxml, but it's the...
6
by: dkyadav80 | last post by:
Hi sir, I'm new about xml, javascript. I have two selection field(html) first is city and second is state. the city and state values should be store in xml file. when user select city then all...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.