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

RE: recursive sorting by element name -> Xalan Issue

Subject: RE: recursive sorting by element name -> Xalan Issue
From: "Scott Trenda" <Scott.Trenda@xxxxxxxx>
Date: Thu, 29 Nov 2007 16:55:10 -0600
RE:  recursive sorting by element name -> Xalan Issue
There we go. Thanks for the clarification, Wendell. I had it ingrained
into my head somewhere never to use self:: for attributes, but I
couldn't quite remember why. The specific self::@attr syntax was the
part I forgot, and couldn't find quickly before I sent my response. Just
to check then, the self:: axis means, absolutely and always, the axis
that the current node exists in? I suppose that's a redundant statement,
now that I think about it. Correct me if I'm wrong then; what I should
have ingrained into my head now regarding the self:: axis is that I
should remember to carefully monitor my usage of common abbreviations
directly afterward. (Or just continue using only the verbose syntax
until the end of the step.) I think that's clear enough to remember
accurately.


> BTW, if you wanted to write for clarity, "+not(@about)" could be
> expressed "number(not(@about))", or if you preferred you could rely
> on what Mike reminded us, that false() sorts before true(), and
> simply say "not(@about)" or "boolean(@about)" depending on which way
> you need it to sort.

number() would be clearer, for sure. I commented on the clarity near the
end of my reply because I was shooting for absolute brevity, and while
+not() was the shortest syntax in the end, I felt it might have been a
little extreme, cutting into the clarity of the code. As Michael pointed
out, there are several other angles you could use (data-type, order) to
get the same results, but none with syntax as razor-slim as mine. :)
Besides the boolean sort-order, that is; I didn't know that before. It
seems like a rather happens-to-work situation, but since it happens to
work, then viva, I'll definitely remember it. :)

~ Scott


-----Original Message-----
From: Wendell Piez [mailto:wapiez@xxxxxxxxxxxxxxxx]
Sent: Thursday, November 29, 2007 4:02 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  recursive sorting by element name -> Xalan Issue

Hi,

At 02:41 PM 11/29/2007, it was written:
>No, self:: implies that the context is a node(), and an attribute
>doesn't show up on that axis. However, since you're applying templates
>to the nodes that will contain the @about attribute, you can omit the
>self:: axis altogether. Try this:
>
><xsl:sort select="+not(@about)"/>

The advice is sound, but the reasoning for it is somewhat garbled.

Attributes do show up on the self:: axis, just as any node does, if
the traversal starts there. Try

@*/self::node()

and you will get back the same set of nodes as from @* without the
"self::node()" step.

To disentangle this, understand that:

"@" in XPath is an abbreviation for an axis specifier, "attribute::".

"*" is a wildcard node test in XPath, which retrieves any node of the
"primary node type of the axis". The primary node type, in turn, is
always an element, except when the axis is the attribute:: axis
('@'), in which case it's an attribute. (Or unless the axis is the
namespace axis, which we'll leave aside.) A similar rule is followed
for a node test by name, such as "section" -- it returns elements
named section, unless the axis is attribute::, in which case we see
"attribute::section" or "@section", and get an attribute by that name.

("node()" is a node test that matches any node at all, irrespective
of what axis it's on.)

If no axis is given at all, an XPath step defaults to the child::
axis, so "section" with no axis given is the same as
"child::section". (This is why select="section" is so different from
select="self::section".)

So "self::*" will return an element if the processing context is an
element, but nothing if it isn't. Similarly,
"self::DictionaryModelDescriptor" returns a DictionaryModelDescriptor
element if the processing context is a DictionaryModelDescriptor
element, nothing if not.

Similarly, "@*" or "attribute::*" will always traverse the attribute
axis from where it starts, and "@about" (aka "attribute::about") will
start at the context node, traverse the attribute axis, and return
any attribute it finds there with the qualified name "about" (due to
XML rules there will never be more than one).

BTW, if you wanted to write for clarity, "+not(@about)" could be
expressed "number(not(@about))", or if you preferred you could rely
on what Mike reminded us, that false() sorts before true(), and
simply say "not(@about)" or "boolean(@about)" depending on which way
you need it to sort.

Saying simply "@about" would sort on the value of that attribute, as
Scott also says.

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
======================================================================

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.