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

Problems with CDATA

  • To: xml-dev@l...
  • Subject: Problems with CDATA
  • From: Ciaran Bruen <cbruen1@y...>
  • 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= ;

cdata
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>

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.