Subject: Re: [xsl] node-id set <-> result document From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 15 Mar 2002 18:55:48 +0000 |
Hi Robert, > I am writing an java app that will resolve general queries over a > given XML data source. I am using Xalan for the XSLT processing. As > I need to do postprocessing of the resulting XML doc, I want the XSL > to return only node ids representing the result doc instead of an > XML document. > > I could image Xalan produce a set of node ids for a given XSLT, send > it to my app and later after postprocessing I will give back those > node ids and let Xalan generate a real XML doc out of it. I think that this approach is going to give you difficulties in terms of performance. It's very tedious for any program, in particular XSLT, to identify nodes on the basis of identifiers, especially if there are a lot of them. I don't know what you're doing precisely, but you might find it more efficient to have XSLT create a replica of the original XML document with annotations indicating which nodes need to be processed, and have that used for post processing and then XSLT transformation. Anyway, if you do continue with your current approach, the difficult is working out an identifier that will be consistent over two runs of different stylesheets over the same XML document. The generate-id() function can't help you here, because the ID generated for a particular node is not guaranteed to be consistent over transformations. Instead, you have to create an identifier that you can replicate. There are lots of ways that you could do it, and which one is best depends on the structure of your XML document. You could generate paths to the nodes - for which you need recursive templates or some processors have an extension function. Or a simple index count. I'd recommend that you use something that you can write in a single XPath, so that you can also use it to create a key for the nodes in the result. For example, to use a simple index count, you could have: <xsl:key name="nodes" match="node()" use="count(preceding::node()|ancestor::node())" /> <xsl:key name="nodes" match="@*" use="concat(count(../preceding::node()|../ancestor::node()), '.', name())" /> and then use: key('nodes', 142) to get the 142nd node and: key('nodes', '142.type') to get the type attribute on it. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] node-id set <-> result docume, Robert Sösemann | Thread | [xsl] javascript problem, stevenson |
Re: [xsl] Cast variable to node-set, David B. Bitton | Date | Re: [xsl] Are xsl:key's best going , Robert Koberg |
Month |