xsl-list
[Top] [All Lists]

RE: XSL & CDATA Processing

2004-06-29 16:11:28
Well, I am running this in a Java Application and
using the built in processor in JDK1.4.2 . 

TransformerFactory factory =
TransformerFactory.newInstance();
Templates template =               
factory.newTemplates(new StreamSource(                
       new FileInputStream(DUPLICATES_XSL)));
Transformer xformer = template.newTransformer();
Source source = new DOMSource(tempDocument);
DocumentBuilder builder=
DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.newDocument();
Result result = new DOMResult(doc);
xformer.transform(source, result);

I have tried using Saxon (again from within the Java
Application) and that generates a different warning
message

Warning: at copy on line 12 of :
  Cannot write an attribute node when no element start
tag is open

Also, the output does not contain any of the
attributes for the Text tag.

<Test>
  <Text>
    <Text.Description>Table File</Text.Description>
    <Text.LongDescription>Table
File</Text.LongDescription>
  </Text>
</Test>

Rohit.
--- Michael Kay <mhk(_at_)mhk(_dot_)me(_dot_)uk> wrote: > Weird. How
are you running this transformation (what
XSLT processor, what
XML parser, and how are you invoking it?)

Michael Kay 

-----Original Message-----
From: Rohit Mathur [mailto:geek_on_line(_at_)yahoo(_dot_)com]

Sent: 29 June 2004 03:21
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] XSL & CDATA Processing

Hi,

I am trying to perform an XSL transform for an XML
Document to remove duplicate Nodes. The XML file
is as
below

<Test>
  <Text LineCount="29" Object="RECORD" Status="?"
Version="000">
    <Text.Description><![CDATA[Table
File]]></Text.Description>
    <Text.LongDescription><![CDATA[Table
File]]></Text.LongDescription>
  </Text>

  <Text LineCount="29" Object="RECORD" Status="?"
Version="000">
    <Text.Description><![CDATA[Table
File]]></Text.Description>
    <Text.LongDescription><![CDATA[Table
File]]></Text.LongDescription>
  </Text>
</Test>


The XSL stylesheet I am using to do this is as
below.

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="1.0" >
  <xsl:output method="xml"
omit-xml-declaration="yes"/>
   <xsl:template match="Text">
      <xsl:if test="not(@Object =
preceding::Text/@Object)">
        <xsl:copy>
          <xsl:apply-templates
select="@*|node()"/>
        </xsl:copy>
      </xsl:if>
   </xsl:template>
   
    <xsl:template match="@*|node()">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

The output generated removes the duplicate node
but
somehow doesn't process the CDATA sections
properly.

<Test>
  <Text LineCount="29" Object="RECORD" Status="?"
Version="000">
    &lt;![CDATA[<Text.Description>]]&gt;Table
File</Text.Description>
    &lt;![CDATA[<Text.LongDescription>]]&gt;Table
File</Text.LongDescription>
  </Text>  
</Test>

I have tried adding a "cdata-section-elements"
section
to the xsl:ouput tag telling it to treat
Text.Description & Text.LongDescription as CDATA.
This creates the following output

<Test>
  <Text LineCount="29" Object="RECORD" Status="?"
Version="000">
   


&lt;![CDATA[<Text.Description><![CDATA[]]]]><![CDATA[>]]><![CD
ATA[Table
File]]></Text.Description>
   


&lt;![CDATA[<Text.LongDescription><![CDATA[]]]]><![CDATA[>]]><
![CDATA[Table
File]]></Text.LongDescription>
  </Text>
</Test>  

Can anyone help me?

Cheers
Rohit.

Find local movie times and trailers on Yahoo!
Movies.
http://au.movies.yahoo.com



--+------------------------------------------------------------------
XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--





--+------------------------------------------------------------------
XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--

 

Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com


<Prev in Thread] Current Thread [Next in Thread>