[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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


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

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
Keywords