Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with XML and cdata-section-elements

Status
Not open for further replies.

andrewthk

Programmer
Nov 16, 2010
2
AU
Hi,

I'm having trouble understanding how to use cdata-section-elements so text within XML element's attribute is ignored by the parser.

Here's the XML:

<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="catalog.xsl"?>
<Results xmlns:xsi=" xsi:noNamespaceSchemaLocation="
<ResultSet id="ID 1" numResults="5" Rating="G">
<Listing title="Title 1" description="Text containing &">
</Listing>
</ResultSet>
</Results>

XSLT:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="<xsl:eek:utput cdata-section-elements="td"/>

<xsl:template match="/">
<html>
<body>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
</tr>
<xsl:for-each select="Results/ResultSet/Listing">
<tr>
<td><xsl:value-of select="@title"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

If anyone could tell me what I'm doing wrong, it will be much appreciated.

Thanks!
 
><Listing title="Title 1" description="Text containing &">
[tt]<Listing title="Title 1" description="Text containing &[red]amp;[/red]">[/tt]
 
Thanks tsuji, however the XML is generated by a third party and I have no control on its content, so description attribute can can contain &.
I need the parser to ignore the content of title and description.
 
No, that's not the biz of xml parser. Do a text file parsing instead. The 3rd party is not doing their job.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top