Wrox Programmer Forums
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2008, 08:45 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default XPATH

I have some questions about which xpath expression to use in order to increase the performance of the xlst transformation.

Given the follwing XML:

<Reports>
<Report xmlns="">
  <Measures>
    <Measure idx="1" heading="Total Pages" />
    <Measure idx="2" heading="Cost" />
  </Measures>
  <Columns>
    <ColGrp heading="Quarter">
      <ColGrp heading="2003">
        <Col heading="Quarter 1" />
        <Col heading="Quarter 2" />
      </ColGrp>
      <ColGrp heading="2004">
        <Col heading="Quarter 1" />
        <Col heading="Quarter 2" />
      </ColGrp>
    </ColGrp>
    <ColGrp>
      <ColGrp>
        <Col heading="Total" />
      </ColGrp>
    </ColGrp>
  </Columns>
</Report>
</Reports>

1 - If this is my current context (i.e. all the ColGrp elements parent of the Col elements)

<ColGrp heading="2003">
<ColGrp heading="2004">
<ColGrp>

How costly is it in terms of speed to use .// to get only the Col whose parent is the current ColGrp?

<td colspan="{count(.//Col)*$msrs}">

Is there a better way of doing the same thing?



2 - I have two variables at the root of my xslt. The nrCol gets the count of all the Col elements and the colSet gets a node set of the all Col elements. What is the difference between using // or descendant in terms of speed?

/Reports/Report/Columns/ColGrp//Col
/Reports/Report/Columns/ColGrp/descendant::Col

<xsl:variable name="nrCol" select="count(/Reports/Report/Columns/ColGrp/descendant::Col)"/>

<xsl:variable name="colSet" select="/Reports/Report/Columns/ColGrp/descendant::Col"/>



3 - If I want to get a node set of all the ColGrp elements parent of the Col element what is fastest way? Again using // or descendant?

/Reports/Report/Columns/descendant::ColGrp[Col]
/Reports/Report/Columns//ColGrp[Col]

Cheers

P
 
Old March 3rd, 2008, 09:01 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It really isn't a good idea to pursue the same question on more than one forum. You've been getting partial answers to your enquiry over on xsl-list; if people there can't solve the problem, then it's unlikely that anyone here can do so.

Remember also that performance depends entirely on which XSLT processor you are using. The way to compare performance of two constructs is to measure it on the processor you intend to use in production. The answers might be radically different for different processors.

In Saxon, .//x and ./descendant::x will in most cases execute exactly the same code. But I've no idea whether that's true for any other processor.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 3rd, 2008, 09:50 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Hi Michael,

I am sorry if asking the same question in another forum (not wrox forum) has caused any incovenience to you or the other members of this forum.

In good faith I have asked the same question in the xslt-list forum because I believe people have different experiences and they can come up with better ideas. I thought it would be a good idea to subscribe to another forum as well.

I do not understand how asking the same question in another forum can cause any problems to you or this forum. I would trully appreciate if you could explain why you feel I should not use two forums? I did not know you used that forum until I posted my question there. But again what is the problem of posting the same question in different forums????

By the way, I am using xslt 1 and IE 6

Also, I cannot see any harm in asking partial questions if it makes it easier for people to undertand your requirements.

I am sorry if this has affected all of you in any way.

P
 
Old March 3rd, 2008, 10:04 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>But again what is the problem of posting the same question in different forums????

It's generally considered bad etiquette because

(a) there will be some overlap in the membership of the forums, which means that you are asking the same people twice

(b) people studying your question on one forum may be wasting their time because you have already received an answer on another forum

(c) if conversations start on both forums, it can can become very confusing because people who are on one but not the other will find it very difficult to follow the thread.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 3rd, 2008, 10:58 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Ok, I can see your point.

In this particular case, I posted a message to this forum with a topic of 'Speed Transformation' on 02/29/2008 but did not receive any replies.

Meanwhile, I was reading Jeni's tutorial on how to use keys and they also mentioned an XSLT forum there. I then decided to subscribe to that forum as well.

Therefore, if I post a topic to this forum but get no answers, then in the interests of good etiquette, would you agree that I could post the same question to another forum as long as I sent a message to the Wrox forum asking the members to disregard my post?

The question is, how can we come up with an agreement that is acceptable to everyone?

If you ask a question in a forum but get no answers for any reason, then surelly we should be entitled to ask that same question on another forum even if the same members are using the other forum since there might be other memebers there not subscribed to the Wrox forum that have more experience in a particular area and may be able to help!!

But anyway, thanks for your input.

Cheers

P





Similar Threads
Thread Thread Starter Forum Replies Last Post
Xpath help please rishid XML 1 February 28th, 2007 03:23 AM
XPATH pallone XSLT 4 November 19th, 2006 07:50 PM
XPath help migake XSLT 2 April 21st, 2006 10:49 AM
Xpath Ma7T XSLT 2 August 16th, 2005 07:54 AM
XPath rupen XML 2 April 19th, 2005 09:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.