xml-xalan-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adrian Sutton" <adrian.sut...@ephox.com>
Subject RE: Getting the context node list
Date Sun, 30 May 2004 23:33:15 GMT
Hi John,
Thanks for the info, incremental XSLT looks like something that may
prove useful.

In terms fo the DTM not updating to accommodate changes in the DOM
that's not a problem for us as we use Xalan only for the full
transformations and not for the ongoing updates to expressions.  We have
our own node tagging system which keeps up with changes to the DOM
accurately.  Because of this tagging system we can get access to the
real Node from the source document pretty easily both inside and outside
of Xalan.

I will take a look at the XSLProcessorContext though I thought I could
already get one of those from the Extension Function using


Adrian Sutton.

-----Original Message-----
From: John Gentilin [mailto:gentijo@eyecatching.com] 
Sent: Saturday, 29 May 2004 4:53 AM
To: Adrian Sutton
Cc: xalan-j-users@xml.apache.org
Subject: Re: Getting the context node list


Back in Jan. I was into this very same problem. Scott Boag pointed me
to a paper on Incremental XSLT which may be a help to you.


Now I don't know the answer to your problem but I wanted to point out
what may be another problem. If you change the DOM in the background, 
the DTM will NOT update so the representation of you document to any 
of the XPath expressions may not make sense. 

There is a method call called getDOMBackPointer which will give you 
a the real Element from the source document which also may be a help.

You may also want top make your Extension Function into an Extension
since the XSLProcessorContext will give you more access than the 

Hope that helps.
John G

Adrian Sutton wrote:

> Hi all,
> (Sorry for the previous email, Outlook decided to send when I tried to
> paste.  Go figure)
> I'm looking for a way to get the complete context node list and am
> generally not getting far.  I need the full context node list instead
> just the actual context node because I need to rerun XPath expressions
> dynamically as the user changes the DOM, but can't run the entire XSLT
> again because of performance issues.  I can get the XPath expression,
> find the context node itself, find all the namespaces in effect, and
> identify all the nodes which are used in the expression, I just can't
> get the full context node list.  Without the full context node list,
> functions like position() don't work correctly.
> For the record, my current test expression is:
> my:quantityOrdered * my:unitPrice
> but the aim is to support any valid XPath expression.
> My first approach was to look for an XPath function or XSLT element I
> could use to get the full context node list but I haven't found
> anything.
> My second approach was to use a custom function and I've had some
> success with that.  My currrent function is:
> 	public String getContext(ExpressionContext context) {
> 		StringBuffer buf = new StringBuffer();
> 		try {
> 			DTMIterator iter =
> context.getXPathContext().getContextNodes();
> 			int handle = iter.getCurrentNode();
> 			if (handle != DTM.NULL) {
> 				Node n =
> iter.getDTM(handle).getNode(handle);
> 				while (n != null) {
> buf.append(XMLFilter.getIDFor(n));
> 					n = getNextNode(iter);
> 					if (n != null) {
> 						buf.append(",");
> 					}
> 				}
> 			}
> 		} catch (Exception e) {
> 			log.error("Failed to create context for xpath
> expression.", e);
> 		}
> 		return buf.toString();
> 	}
> XMLFilter.getIDFor(n) gives a String that can be used to retrieve the
> node from the DOM later on (though various magic incantations we've
> discovered).  For the first node in the context list this works
> perfectly, unfortunately it appears that the DTMIterator I'm using is
> the same one that Xalan is using and so the method causes Xalan to
> over all but the first element (because getContext() has already
> iterated through the nodes).  When I try to reset the position of the
> iterator I get the exception:
> This NodeSetDTM can not iterate to a previous
> node!>java.lang.RuntimeException: This NodeSetDTM can not iterate to a
> previous node!
> 	at
> ator.java:627)
> 	at
> ava:364)
> 	at
> )
> 	at
> java:499)
> 	at
> thExtensions.java:51)
> I notice that there is a DTMIterator.setShouldCacheNodes(boolean)
> which enables random access to the iterator but calling it seems to
> reset the iterator such that it no longer contains any nodes.  Is
> any property to set to make all iterators random access enabled?  I've
> tried setting:
> http://xml.apache.org/xalan/features/incremental
> TransformerFactoryImpl.FEATURE_OPTIMIZE
> and
> http://xml.apache.org/xalan/features/optimize
> to false with no success.
> Alternately, is there some other approach I'm missing?
> Regards,
> Adrian Sutton.

John Gentilin
Eye Catching Solutions Inc.
18314 Carlwyn Drive
Castro Valley CA 94546

    Contact Info
Ca Office 1-510-881-4821
NJ Office 1-732-422-4917

View raw message