[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Problems with CDATA


xsl recordcount
 > 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>

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.