Firstly, the fact that ./v[$p] doesn't work, but ./v[$p + 0] does work,
means that the value of $p is not a number. Perhaps it is a string, or
perhaps it is a result tree fragment. Either way, you would probably get an
immediate performance improvement by changing it to be a number, to avoid
the conversion costs each time the value is used.
Incidentally, the expression "./v" is exactly the same as "v". If your
processor is particularly stupid, the more complex expression might take
longer to evaluate.
It's of course entirely dependent on your XSLT processor whether the
expression v[$p] takes constant time, or time proportional to $p. It looks
as if in your case, it's taking time proportional to $p. That would be the
case if you were using Saxon. In Saxon you could get round this by using a
variable:
<xsl:variable name="vseq" select="v"/>
<xsl:for-each....
<xsl:value-of select="$vseq[$p]"
But that wouldn't necessarily help on a different processor. Note also that
this only works if $p is known at compile time to be a number - so you need
to fix that problem first.
Michael Kay
http://www.saxonica.com/
-----Original Message-----
From: krzysztof(_at_)cieniuch(_dot_)net
[mailto:krzysztof(_at_)cieniuch(_dot_)net]
Sent: 25 August 2006 12:20
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] xslt performance issue position() function
used in predicate very slow
Hi,
I'm processing xml files that have 150kB size they are
composed from xml blocks that contain 350 elements with int
values here is example
< obj name="obj1">
<v>1</v>
<v>2</v>
<v>3</v>
....
<v>350</v>
</obj>
obj blocks are repeated many times
in general my xslt selects some set of <v> rows and saves
in csv format e.g. select 1,2,3,4,15,28,71,17,19 and save to
csv in my xslt I'm using below expression to select v rows
<xsl:value-of select="./v[position()=$p]"/>
( in for-each loop I assign value to $p variable)
on P4 2.8 Ghz 512MB ram it takes 20 seconds! to parse 150KB file !!!
if I comment out this line it takes 1 second so definitely
it's issue with
position()
and selecting this v values.
BTW abbreviated version doesn't wok i.e. select="./v[$p]"
but select="./v[$p+0]" works is this some bug ???
Thanks for any tips how to improve performance
Chris
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--