|
|
If the XML is a file called, x.xml:
Then some XSLT might be called, x.xsl:
Then opening x.xml, in Microsoft Internet Explorer 5 on up, produces as a result:
Msxml 3.0 might not report the reserved xml namespace, in this case, but it should. Again, the "version=" is some arbitrary number, here. It's probably best just to keep it at "1.0". This calls upon the namespace "axis". There's another axis, called parent, which is also repeatedly used, here. These are XPath axes. They return a set of nodes, or node-set. The namespace axis can't be used with attributes, only elements. The list it returns is for all namespaces that could be used by that element. For squirrel, there's actually four that are available:
However, the XPath query used by the for-each, select, it essentially performing an intersection join on two different flat lists of namespaces. One list is for the name element which has text of, squirrel. But a second list is for the name element containing, hawk. Hawk only has three available namespaces. So the intersection (in this particular case to the same effect as a SQL inner join) are just those three namespaces that the two lists share in common. So that's what the for-each is looping through - a list of three available namespaces shared between two different nodes. Let's look at the other axis, used here - parent:
Parent could return a nodeset, not just a flat list like the special case of, namespace. Here name is the actual name of an element. There are elements, in the XML, called - name. And the brackets contain what in SQL might be a WHERE clause, or generally - a conditional. The period is a XPath shorthand, in the case of the parent axis, for the current element node. So this is a nested conditional, looking up to a parent element called, name, and then qualifing that as having the text of - squirrel. There's only one squirrel, so it returns the list of available namespaces for only one element/node. Why use the parent axis? It's unique to the design of the whole namespace model. The for-each is going through available namespaces. But the element is treated as the parent of the available namespaces. So to test the actual node, one needs to look at the parent of what's returned by the namespace axis. It's a bit confusing - but namespaces can be.
Position is another built-in XPath function. These nodesets are returned in a particular order. The position function gives the ordinal position, counting from 1. The letter, n, and the parentheses, are just inserted text. You can see, again, the mix of "xsl" commands with HTML tags and assorted text in one of these XSLT transforms. And continuing on: |