OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] Problems with CDATA

[ Lists Home | Date Index | Thread Index ]

 > The first problem was that it was not keeping any of the CDATA sections around any elements - it was simply removing them and just copying the text inside the sections.  
 
That's correct behaviour. CDATA is considered to be just an input convenience, to save you using lots of entity and character references for special characters. If there aren't any special characters, then the CDATA brackets are just noise.
 
 I then added cdata-section-elements="UNIQUEJVID" and cdata-section-elements="TITLE" (in a new line) to the xsl:output section of the xsl. This returned the CDATA section around these element but incorrectly - as in below:  
 
This looks like a quirk of the XSLT processor you are using, you should report it on the support channel for that processor (or at the very least, tell us which processor you are using.)
 
Michael Kay
http://www.saxonica.com/
 
 
 
<ROW id="1">
  <UNIQUEJVID><![CDATA[
]]><![CDATA[    699911
  ]]></UNIQUEJVID>
<ROW id="2">
  <UNIQUEJVID><![CDATA[
    7]]><![CDATA[03750
]]></UNIQUEJVID>
 
It's adding whitespace to some, adding 2 CDATA sections to others, and also splitting the text value and adding CDATA around each piece!! Does anyone know why this might be?? (See my xml and xsl below).
 
Cheers,
Ciaran
 
My XML:
<query_results>
  <header>
    <QUERY><![CDATA[+soccode1:112*]]></QUERY>
    <SERVER><![CDATA[Server Name]]></SERVER>
    <EXECUTION_TIME>0</EXECUTION_TIME>
    <TRANSPORT_TIME>468</TRANSPORT_TIME>
    <SERVICE_URI><![CDATA[http://www.uriname.com:8080/axis/ServiceProvider]]></SERVICE_URI>
    <SEARCH_PARAMETERS>
      <ISCO>1229</ISCO>
      <COUNTRY>%</COUNTRY>
      <REGION>%</REGION>
      <DATE>28%2F1%2F2006</DATE>
      <TITLE/>
      <STARTRECORD>1</STARTRECORD>
      <PAGESIZE>10</PAGESIZE>
    </SEARCH_PARAMETERS>
  </header>
  <results>
    <META>
 <RECORDCOUNT>3</RECORDCOUNT>
 <COLUMNSNUMBER>7</COLUMNSNUMBER>
 <STARTRECORD>1</STARTRECORD>
 <PAGESIZE>10</PAGESIZE>
    </META>
    <ROWS>
 <ROW id="1">
   <UNIQUEJVID><![CDATA[699911]]></UNIQUEJVID>
   <TITLE><![CDATA[Manager - Livestock]]></TITLE>
   <DESCRIPTION><![CDATA[Working in a busy dairy farm.]]></DESCRIPTION>
   <SALARY_CURRENCY><![CDATA[BRITISH POUND]]></SALARY_CURRENCY>
   <SALARY_MIN><![CDATA[null]]></SALARY_MIN>
   <SALARY_MAX><![CDATA[ú15,000 PER ANNUM]]></SALARY_MAX>
   <SALARY_PERIOD><![CDATA[ANNUALLY]]></SALARY_PERIOD>
   <OPTIONAL_DATA>
   <OPT_REGION><![CDATA[CO. DOWN]]></OPT_REGION>
     <OPT_LOCATION><![CDATA[DOWNPATRICK]]></OPT_LOCATION>
     <OPT_SUBLOCATION><![CDATA[Armagh]]></OPT_SUBLOCATION>
     </OPTIONAL_DATA>
 </ROW>
 <ROW id="2">
 ...
 </ROW>
      </ROWS>
  </results>
  <header>
  ...
  </header>
  <results>
  ...
  </results>
  etc.
</query_results>
 
My xsl:
<?xml version="1.0" encoding = "ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" cdata-section-elements="UNIQUEJVID"/>
<xsl:output method="xml" cdata-section-elements="TITLE"/>
  <xsl:template match="/">
    <query_results>
      <xsl:apply-templates />
      <xsl:copy-of select = "//EXTRA" />
    </query_results>  
  </xsl:template>
  <xsl:template match="query_results">  
    <xsl:apply-templates select="header"/>
      <results>
      <xsl:apply-templates select="results/META"/>
      <ROWS>
 <xsl:apply-templates select="results/ROWS/ROW"/>
      </ROWS>
    </results>
  </xsl:template>
 
  <xsl:template match="header">
    <xsl:if test="position()=1">
      <xsl:copy-of select = "." />
    </xsl:if>
  </xsl:template>
 
  <xsl:template match="META">
    <xsl:if test="position()=1">
      <META>
 <RECORDCOUNT><xsl:value-of select="sum(//RECORDCOUNT)" /></RECORDCOUNT>
 <COLUMNSNUMBER><xsl:value-of select="COLUMNSNUMBER" /></COLUMNSNUMBER>
 <STARTRECORD><xsl:value-of select="STARTRECORD" /></STARTRECORD>
 <PAGESIZE><xsl:value-of select="PAGESIZE" /></PAGESIZE>   
      </META>
    </xsl:if>
  </xsl:template>
  
  <xsl:template match="ROW"> 
    <ROW>
      <xsl:attribute name="id"><xsl:number level="any" count="ROW" format="1"/></xsl:attribute>
      <xsl:copy-of select="node()"/>
    </ROW>
  </xsl:template> 
   
</xsl:stylesheet>




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS