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

RE: thoroughly confused about node() matching

Subject: RE: thoroughly confused about node() matching
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Mon, 3 Mar 2003 16:49:45 -0600
apply templates namespace
> Lars Huttar wrote:
> > As you point out, though, the spec disagrees with Kay
> > about child::node() matching namespace nodes.  Maybe the
> spec writers
> > forgot about namespace nodes when they wrote that??
>
> Namespace nodes are not on the child axis. I'd think node()
> would match namespace nodes if applied on the namespace axis.
>
> J.Pietschmann

I totally agree... that's why I'm saying, since (I thought) the spec
writers were talking about "node()" as a whole pattern,
with no specified axis (and therefore using the "child" axis),
why did they say

 o  node() matches any node other than an attribute node and the root node

instead of

 o  node() matches any node other than an attribute node, the root node,
    and namespace nodes

?
Did they really mean that namespace nodes are matched (in which case
they're saying Kay is wrong), or did they make a mistake?


But now that I look at the spec again, (section 5.2,
http://www.w3.org/TR/1999/REC-xslt-19991116#patterns)
I'm not sure their discussion about patterns applies only to the child axis.
I'm too fuzzy in my understanding of patterns.  If someone tried
      <xsl:apply-templates select="namespace::*"/>
wouldn't this match a template like
  <xsl:template match="node()">
    ...
  </xsl:template>
?

I tried this just now, to see what would happen.  To my surprise,
it seems that the above template doesn't match namespace nodes,
even if they are called with select="namespace::*".  However I'm
not at all confident that I've done this right.  Can anybody
straighten me out?

Here's my XML:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="test-namespace-node.xsl"?>
<foo xmlns:r="blah" xmlns="kdjf">
  <bar xmlns="54kk" xmlns:g="lksd">2</bar>
</foo>


And my stylesheet:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">
  <xsl:output method="html"/>

  <xsl:template match="/">
    <html>
      <body>
        <xsl:apply-templates select="*" />
      </body>
    </html>
  </xsl:template>

  <xsl:template match="*">
    <xsl:value-of select="name()" /> [
    <xsl:apply-templates select="namespace::*" mode="nodenaming" /> ]
    <xsl:apply-templates select="*" />
  </xsl:template>

  <xsl:template match="node()" mode="nodenaming">
    <p>Node name: <xsl:value-of select="."/></p>
  </xsl:template>

</xsl:stylesheet>


The output I get is:

<html>
<body>foo [
    http://www.w3.org/XML/1998/namespaceblahkdjf ]
    bar [
    http://www.w3.org/XML/1998/namespaceblah54kklksd ]
    </body>
</html>

which says to me that
  <xsl:apply-templates select="namespace::*" mode="nodenaming" />
is selecting the namespace nodes but no matching template is
found (not even <xsl:template match="node()">).  (And so the default
template is used for the namespace nodes.)  That's weird... why
doesn't the "node()" pattern match the namespace nodes?  This would
contradict what I understand the spec as saying.

I also tried changing
  <xsl:template match="node()" mode="nodenaming">
to
  <xsl:template match="namespace::node()" mode="nodenaming">
but that was an Invalid Match Pattern. (Saxon says: Axis in pattern
must be child or attribute.  OK, fair enough... but does that mean
templates can only ever match children or attributes?)

The above was done using IE (with MSXML 3) unless otherwise specified.
Saxon gave me different results:
<html>
   <body>foo [
       ]
      bar [
       ]

   </body>
</html>

I.e. no output at all for the namespace nodes.  Weirder!
I'm confused.  Is Saxon telling me that <xsl:apply-templates
 select="namespace::*" /> doesn't select any namespace nodes??
I tried adding Num: <xsl:value-of select="count(namespace::*)" />
to the output inside the match="*" template, and it verified in both
IE and Saxon that the number of namespace nodes for foo and bar
was 3 and 4, respectively.

So can anyone tell me why IE doesn't want to apply my intended
template to the namespace nodes -- substituting a default instead --
and Saxon won't apply any templates to them?

Thanks...
Lars



 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.