XSLT 1.0: restrict entries in a nodeset

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2011-01-10T15:49:10Z Indexed on 2011/01/10 15:54 UTC
Read the original article Hit count: 237

Filed under:
|
|

Hi,

Being relatively new to XSLT I have what I hope is a simple question.

I have some flat XML files, which can be pretty big (eg. 7MB) that I need to

make 'more hierarchical'. For example, the flat XML might look like this:

<D0011>

.... ....

and it should end up looking like this:

<D0011>

.... ....

I have a working XSLT for this, and it essentially gets a nodeset of all the b

elements and then uses the 'following-sibling' axis to get a nodeset of the

nodes following the current b node (ie. following-sibling::*[position()

=$nodePos]). Then recursion is used to add the siblings into the result tree

until another b element is found (I have parameterised it of course, to make

it more generic).

I also have a solution that just sends the position in the XML of the next b

node and selects the nodes after that one after the other (using recursion) via

a *[position() = $nodePos] selection.

The problem is that the time to execute the transformation increases

unacceptably with the size of the XML file. Looking into it with XML Spy it

seems that it is the 'following-sibling' and 'position()=' that take the time

in the two respective methods.

What I really need is a way of restricting the number of nodes in the above

selections, so fewer comparisons are performed: every time the position is

tested, every node in the nodeset is tested to see if its position is the right one. Is there a way to do that ? Any other suggestions ?

Thanks,

Mike

© Stack Overflow or respective owner

Related posts about Performance

Related posts about xslt