RE: [xsl] Updating xml - difference between MSXML and Xalan

Subject: RE: [xsl] Updating xml - difference between MSXML and Xalan
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 26 May 2006 09:27:50 +0100
In XSLT 1.0, the effects of starting a transformation at a node other than
the root are not defined, so products can do what they like.

In 2.0, "/" is defined to match the root node even if the transformation
started deep within the document.

Michael Kay 

> -----Original Message-----
> From: Pete & Angie Taylor [mailto:pandatay@xxxxxxxxxxxxx] 
> Sent: 25 May 2006 21:44
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Updating xml - difference between MSXML and Xalan
> Dear List,
> We have a working document that can get large (100kb + ) and 
> is frequently updated by being transformed and then 
> completely replaced by the transformation result - a sort of 
> xslt master file update.
> I am trying to improve performance by only transforming the 
> nodes that need to change, avoiding the high cost of 
> repeatedly copying the 90% plus that does not change each time.
> The basic idea is for my application code to identify one or 
> more templates that handle the changes (name startswith 
> "replace"), find all nodes that are matched by any of these 
> templates, transform each node, and replace each node with 
> the result of its transformation. (I.e. to do a number of 
> very small translations of particular nodes, rather than one 
> very large translation of the whole document.)
> For example, if my working document looks like this -
> <a>
>     <b>before</b>
> </a>
> and I have a stylesheet with an identity template and a 
> template like this -
> <xsl:template name="replace1" match="/a/b">
>     <xsl:copy>after</xsl:copy>
> </xsl:template>
> then my application finds the template named "replace1", 
> finds the node that is matched by "/a/b" and transforms and 
> replaces just that node. The result is -
> <a>
>     <b>after</b>
> </a>
> When I transform the non-root <b> node rather than the whole 
> document, MSXML matches it with the "replace1" template, and 
> I get the result I expect. I can demonstrate a huge saving 
> when repeatedly making small updates to a large document.
> But when I try to transform the <b> node in Xalan 
> (transformer.transform(new
> DomSource(node)) ) it fails to match my <b> node with the 
> path "/a/b". I can only get my <b> node to be matched by a 
> template with a match attribute of exactly "b".
> My question is: if I transform a node other than the root 
> node of an xml document using xslt, should the node be 
> matched by a template which has a match starting from the 
> root? (Should my <b> node be matched by my "/a/b"
> template?) Any idea why Xalan doesn't seem to do it? Is it 
> me? (It usually
> is!)
> Thanks in advance - and thanks for many many interesting 
> posts in the past.
> Pete Taylor

Current Thread