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

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Problems with CDATA

[ Lists Home | Date Index | Thread Index ]
  • To: xml-dev@lists.xml.org
  • Subject: Problems with CDATA
  • From: Ciaran Bruen <cbruen1@yahoo.com>
  • Date: Thu, 9 Mar 2006 16:00:12 +0000 (GMT)
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=emmx9/TL7F0yVi1prFhyx7oLv8k5bLZvatzaccTDOWMJmn8Yv4AlaFMwfNn7oE4fe6jPSa4gvpxHMkpQrLm0N0FJ6ySeYCDZADR5N80Dopk4iGojWG53I7MhkFd9Vv3h/LVVYXMqZ9hlWbaiseC1rQKdrHhchn6FeUBlpW6521M= ;

Hi - I'm having problems transforming an XML document into another XML document. I'm using Tomcat/jsp to call a web service, then calling a java bean (which uses javax) to transform the returned xml. Originally the system was calling the web service once using one search parameter. However I now have to call the service multiple times and combine the returned XML, each of which is a fully formed document. I am combining the XML in the JSP page using string manipulation, then once I have this I apply my new XSL to give me one overall document.
 
When I apply the XSL in my XML editor the output is fine, but when I write the returned xml to a log file from the jsp page it's fouled up. 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. 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:
 
<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