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

RE: XSL & CDATA Processing

Subject: RE: XSL & CDATA Processing
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Wed, 30 Jun 2004 09:56:02 +0100
xsl cdata processing
> 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 can't comment on why Xalan should produce the result it does, but I
suspect that you would get better results by not using a DOMSource. I think
it's true for most XSLT processors that they work best if you allow them to
build the tree themselves using their own native tree structure. Unless you
have a very good reason for using a DOM, use a SAXSource or StreamSource
when using JAXP.

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

This appears to be a previously unreported Saxon bug. The (very complex)
algorithm for sorting DOM nodes into document order, which is needed here
because of the union expression select="@*|node()", is not dealing correctly
with node-sets that contain a mixture of attribute and non-attribute nodes.

Walking through this in the debugger has reminded me quite how inefficient
the DOM is, compared with Saxon's native input tree. It's really best
avoided! (though I will of course fix the bug).

You can circumvent the problem (and save Saxon a lot of work) by writing

<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/>

Scope here for an internal optimization!

Michael Kay


Current Thread

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