472,960 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,960 software developers and data experts.

Matching preceding-sibling axis is SLOWWWW!

I have an XSLT transformation that involves a template with

match =
"w:p[ancestor::w:body][preceding-sibling::*[1][self::aml:annotation/@w:type
= 'Word.Bookmark.Start']]"

What I'm matching on is a w:p element that is:

1.) Within a w:body element (at some level).
2.) Immediately preceeded by an aml:annotation element (whose @w:type is
'Word.Bookmark.Start').

This would seem to be a fairly simple match and, in fact, when I run it on a
fairly small XML input file it finishes quickly. However, when I run it on a
large (>6MB) XML file it appears to hang -- at least it has so far never
finished and I've given it an hour or so to try on a 1GB RAM, 2GHz machine.

This performance problem would seem to indicate that MSXML (the .Net
Framework 1.1 version) doesn't do much/any optimization on axis references.
I'm guessing that it is synthesizing a node set of the entire
preceding-sibling axis (which may be thousands of elements), then indexing
into it using [1]!

I'm off to finding a workaround, perhaps using xsl:key to speed things up,
but of course xsl:key has its own set of MSXML problems. Does anyone have
any suggestions how I might avoid this problem?

Thanks in advance,
Bill

PS - BTW, I'm trying to process a rather large Word 2003 doc via its WordML
representation.
Nov 12 '05 #1
7 2240
Bill Cohagan wrote:
I have an XSLT transformation that involves a template with

match =
"w:p[ancestor::w:body][preceding-sibling::*[1][self::aml:annotation/@w:type
= 'Word.Bookmark.Start']]"
That's really bad match pattern. Patterns are meant to be simple due to
XSLT processing model. Instead move selection logic to applying step:

<xsl:apply-templates
select="w:p[ancestor::w:body][preceding-sibling::*[1][self::aml:annotation/@w:type
= 'Word.Bookmark.Start']]"/>
....

<xsl:template match="w:p">

To avoid clashes you can use modes:

<xsl:apply-templates
select="w:p[ancestor::w:body][preceding-sibling::*[1][self::aml:annotation/@w:type
= 'Word.Bookmark.Start']]" mode="bookmark"/>
....

<xsl:template match="w:p" mode="bookmark">
I'm off to finding a workaround, perhaps using xsl:key to speed things up,
but of course xsl:key has its own set of MSXML problems. Does anyone have
any suggestions how I might avoid this problem?


Never heard of any problems with keys in MSXML. Yes, keys are usually
preferred way (they allow direct access to nodes instead of tree
selection with the price of building the index).

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
Bill Cohagan wrote:
I have an XSLT transformation that involves a template with

match =
"w:p[ancestor::w:body][preceding-sibling::*[1][self::aml:annotation/@w:type
= 'Word.Bookmark.Start']]"
That's really bad match pattern. Patterns are meant to be simple due to
XSLT processing model. Instead move selection logic to applying step:

<xsl:apply-templates
select="w:p[ancestor::w:body][preceding-sibling::*[1][self::aml:annotation/@w:type
= 'Word.Bookmark.Start']]"/>
....

<xsl:template match="w:p">

To avoid clashes you can use modes:

<xsl:apply-templates
select="w:p[ancestor::w:body][preceding-sibling::*[1][self::aml:annotation/@w:type
= 'Word.Bookmark.Start']]" mode="bookmark"/>
....

<xsl:template match="w:p" mode="bookmark">
I'm off to finding a workaround, perhaps using xsl:key to speed things up,
but of course xsl:key has its own set of MSXML problems. Does anyone have
any suggestions how I might avoid this problem?


Never heard of any problems with keys in MSXML. Yes, keys are usually
preferred way (they allow direct access to nodes instead of tree
selection with the price of building the index).

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #3
Oleg
Thanks for the response. I don't know why you consider it a "bad pattern"
as that's what XSL is all about. The XSLT processing model doesn't
discourage nontrivial match patterns although it's certainly possible that
the MS implementation does. Certainly it's a nontrivial pattern as are many
others in my application; however it is the only one that causes the .Net
MSXML to hang/nonterminate.

As a sanity check I ran this particular template against Instant Saxon and
it completes in less than a minute -- so clearly it's not a limitation of
the language, but of the implementation. I also moved the predicates into
the template as you suggested and it still hangs in .Net.

Regards,
Bill

PS - I've encountered several xsl:key errors for which hot fixes were later
supplied. The latest problem (with KB article pending) has to do with using
current() within a predicate of a match pattern in an xsl:key. If you'd like
I'll let you know when it gets posted. The workaround for that one requires
the use of c# script in the template rather than using xsl:key. MS seems to
be not anxious to spend resources on fixing their XSL tools, although
they've been helpful in finding workarounds.
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Bill Cohagan wrote:
I have an XSLT transformation that involves a template with

match =
"w:p[ancestor::w:body][preceding-sibling::*[1][self::aml:annotation/@w:type = 'Word.Bookmark.Start']]"
That's really bad match pattern. Patterns are meant to be simple due to
XSLT processing model. Instead move selection logic to applying step:

<xsl:apply-templates

select="w:p[ancestor::w:body][preceding-sibling::*[1][self::aml:annotation/@
w:type = 'Word.Bookmark.Start']]"/>
...

<xsl:template match="w:p">

To avoid clashes you can use modes:

<xsl:apply-templates
select="w:p[ancestor::w:body][preceding-sibling::*[1][self::aml:annotation/@
w:type = 'Word.Bookmark.Start']]" mode="bookmark"/>
...

<xsl:template match="w:p" mode="bookmark">
I'm off to finding a workaround, perhaps using xsl:key to speed things up, but of course xsl:key has its own set of MSXML problems. Does anyone have any suggestions how I might avoid this problem?


Never heard of any problems with keys in MSXML. Yes, keys are usually
preferred way (they allow direct access to nodes instead of tree
selection with the price of building the index).

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #4
Oleg
Thanks for the response. I don't know why you consider it a "bad pattern"
as that's what XSL is all about. The XSLT processing model doesn't
discourage nontrivial match patterns although it's certainly possible that
the MS implementation does. Certainly it's a nontrivial pattern as are many
others in my application; however it is the only one that causes the .Net
MSXML to hang/nonterminate.

As a sanity check I ran this particular template against Instant Saxon and
it completes in less than a minute -- so clearly it's not a limitation of
the language, but of the implementation. I also moved the predicates into
the template as you suggested and it still hangs in .Net.

Regards,
Bill

PS - I've encountered several xsl:key errors for which hot fixes were later
supplied. The latest problem (with KB article pending) has to do with using
current() within a predicate of a match pattern in an xsl:key. If you'd like
I'll let you know when it gets posted. The workaround for that one requires
the use of c# script in the template rather than using xsl:key. MS seems to
be not anxious to spend resources on fixing their XSL tools, although
they've been helpful in finding workarounds.
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Bill Cohagan wrote:
I have an XSLT transformation that involves a template with

match =
"w:p[ancestor::w:body][preceding-sibling::*[1][self::aml:annotation/@w:type = 'Word.Bookmark.Start']]"
That's really bad match pattern. Patterns are meant to be simple due to
XSLT processing model. Instead move selection logic to applying step:

<xsl:apply-templates

select="w:p[ancestor::w:body][preceding-sibling::*[1][self::aml:annotation/@
w:type = 'Word.Bookmark.Start']]"/>
...

<xsl:template match="w:p">

To avoid clashes you can use modes:

<xsl:apply-templates
select="w:p[ancestor::w:body][preceding-sibling::*[1][self::aml:annotation/@
w:type = 'Word.Bookmark.Start']]" mode="bookmark"/>
...

<xsl:template match="w:p" mode="bookmark">
I'm off to finding a workaround, perhaps using xsl:key to speed things up, but of course xsl:key has its own set of MSXML problems. Does anyone have any suggestions how I might avoid this problem?


Never heard of any problems with keys in MSXML. Yes, keys are usually
preferred way (they allow direct access to nodes instead of tree
selection with the price of building the index).

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #5
Bill Cohagan wrote:
Thanks for the response. I don't know why you consider it a "bad pattern"
as that's what XSL is all about. The XSLT processing model doesn't
discourage nontrivial match patterns although it's certainly possible that
the MS implementation does.
Well, it doesn't say it directly, but from the decription of the
processing model "A node is processed by finding all the template rules
with patterns that match the node, and choosing the best amongst them"
it's easy to see that having complex patterns is the way to slow down
the transformation. That's pretty valid pattern though, but quite
ineffective. Why not apply templates to only nodes you are interested to
process?
Certainly it's a nontrivial pattern as are many
others in my application; however it is the only one that causes the .Net
MSXML to hang/nonterminate.
..NET or MSXML? That's definitely a bug anyway, provide a repro please.
As a sanity check I ran this particular template against Instant Saxon and
it completes in less than a minute -- so clearly it's not a limitation of
the language, but of the implementation.
Which version of .NET you are using? Try the latest one - there were
solid improvements in the resent release.
I also moved the predicates into
the template as you suggested and it still hangs in .Net.
So that's not the reason. It should be something else.
If you'd like
I'll let you know when it gets posted.


Yeah, that would be interesting.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #6
Oleg
See responses below

Thanks,
Bill
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:uA**************@TK2MSFTNGP09.phx.gbl...
Bill Cohagan wrote:
Thanks for the response. I don't know why you consider it a "bad pattern" as that's what XSL is all about. The XSLT processing model doesn't
discourage nontrivial match patterns although it's certainly possible that the MS implementation does.
Well, it doesn't say it directly, but from the decription of the
processing model "A node is processed by finding all the template rules
with patterns that match the node, and choosing the best amongst them"
it's easy to see that having complex patterns is the way to slow down
the transformation. That's pretty valid pattern though, but quite
ineffective. Why not apply templates to only nodes you are interested to
process?

[Bill] I *am* applying templates to the nodes I want to process. Please
clarify what you mean by this.
Certainly it's a nontrivial pattern as are many
others in my application; however it is the only one that causes the ..Net MSXML to hang/nonterminate.


.NET or MSXML? That's definitely a bug anyway, provide a repro please.


[Bill] I'm using the .Net Framework 1.1, so whatever the XML/XSL engine is
in that release. I say "hang" because it's never finished, although
certainly it might if I give it a few days (or weeks or ...). I can email
you a repro if you'd like. What email address should I use?
As a sanity check I ran this particular template against Instant Saxon and it completes in less than a minute -- so clearly it's not a limitation of the language, but of the implementation.
Which version of .NET you are using? Try the latest one - there were
solid improvements in the resent release.
I also moved the predicates into
the template as you suggested and it still hangs in .Net.


So that's not the reason. It should be something else.


[Bill] Perhaps it is. As time allows I'll try to isolate the problem by
trimming the input. Perhapse it's another bug rather than just a performance
issue.
If you'd like
I'll let you know when it gets posted.
Yeah, that would be interesting.


[Bill] Will do. Meanwhile if you google Cohagan XSL Key (looking at groups)
you should see some of the past issues I've encountered.
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #7
Bill Cohagan wrote:
[Bill] I *am* applying templates to the nodes I want to process. Please
clarify what you mean by this.
Well, I meant moving complexity to <xsl:apply-templates> to simplify
template matching:

<xsl:apply-templates
select="w:p[ancestor::w:body][preceding-sibling::*[1][self::aml:annotation/@w:type
= 'Word.Bookmark.Start']]"/>
....

<xsl:template match="w:p">

instead of

<xsl:apply-templates/>

....

<xsl:template match =
"w:p[ancestor::w:body][preceding-sibling::*[1][self::aml:annotation/@w:type
= 'Word.Bookmark.Start']]">

In the former case the selection is evaluated only once, while in former
case it evaluates on each node being matched durring the
transformation (potentially hundreds or thousands times).
[Bill] I'm using the .Net Framework 1.1, so whatever the XML/XSL engine is
in that release. I say "hang" because it's never finished, although
certainly it might if I give it a few days (or weeks or ...). I can email
you a repro if you'd like. What email address should I use?


Just remove NO!SPAM!PLEASE from this post address.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ahogue at theory dot lcs dot mit dot edu | last post by:
Hello - Is there any way to match complex subtree patterns with XPath? The functions I see all seem to match along a single path from root to leaf. I would like to match full subtrees. For...
1
by: Dave Keays | last post by:
I am setting-up an experimental web service using Apache Axis but I'm having problems. AXIS can't find a library that I've verified exists on my computer and that CLASSPATH points to it. I'm using...
0
by: Bill Cohagan | last post by:
I have an XSLT transformation that involves a template with match = "w:p]" What I'm matching on is a w:p element that is: 1.) Within a w:body element (at some level). 2.) Immediately...
3
by: Jacky Zhu | last post by:
Hi all, I am having a problem trying to consume a webservice that is developed on ..Net. I can access it without any problem using a .net client, but when I use a java client (based on Axis...
3
by: parrot toes | last post by:
Summary: I have been trying to make requests of a web service provided by Axis using a dotnet client with code generated by wsdl.exe and have been getting exceptions when trying to process the...
4
by: nawrin22 | last post by:
hi.. I am a niwebie in 'AXIS' . but i had correctly installed it without any problem with the help of 'apache.axis.install.pdf' and also tested the examples under 'samples\userguide' directoy...
3
by: Jeremy Chapman | last post by:
I've writtin a very simple web service in axis which returns an array of classes. I consume it in a .net app. When receiving the response, my .net app generates an error "Cannot assign object...
0
by: TraceyAnnison | last post by:
I wonder if you can help me - I'm new to this, and working in a project that has already been configured to work with Axis. We have a Java project built with the Spring framework, in order to...
0
by: Just_a_fan | last post by:
Some folks have searched, from time to time, for a dual axis MSChart with different scales on the two Y axes. The sample, extracted from running code I wrote, produces a graph with MSChart (VB9)...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.