[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Is this node, the document root... best test?

Subject: Re: Is this node, the document root... best test?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 20 Oct 2003 13:17:38 -0400
node to document
Steve,

At 12:46 PM 10/20/2003, you wrote:
I'm not sure what's holding up my posts (I see responses before I see my post ;-) but,

I thought I'd post my findings on a quick n dirty test...

testing every node in an xml document,...
...start timer 1,
...30 times <xsl:if test=". = /"><!-- just time test --></xsl:if>
...stop timer 1,

...start timer 2,
...30 times <xsl:if test="not(parent::*)"><!-- just time test --></xsl:if>
...stop timer 2,

compare timers...

I found that the first test (timer 1), was routinely 10-30ms faster than the second.
Note:
- my test nodes were between 0-7 levels deep, 500-1,000 nodes in total...
- obvious gc / memory cleanup results were omited
- timer execution times are included, but pressumed minimal, and relatively average.

I'm not sure these tests are very meaningful ... I suspect there are many variables in play besides those that you're testing, including which processor you are using.


In any case, the test ". = /" is not a dependable test: it tests true if the value of the context node is the same as the value of the root node, which will be the case for both the root node and the document element, and sometimes for other elements as well, as in:

<hey>
  <this>
    <is>nuts</is>
  </this>
</hey>

The values of the root, of the <hey>, <this> and <is> elements are all the same: "nuts". So .=/ tests true for all these cases.

So, by "document root" do you mean the actual root of the XPath tree representation of an XML document, or the "document element", namely that element that contains all the others, sometimes called the "root element" in XML?

test="parent::*" will test false for either the document root or the document element, even though the document element is a child of the root. This is because the primary node type of the parent axis is an element, and neither of these nodes have an element parent.

test="parent::node()" will test true for the document element (it has a parent, namely the root node) but not for the root node (which has no parent).

Cheers,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.