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

Re: Finding out if the current node is an attribute no

Subject: Re: Finding out if the current node is an attribute node
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Mon, 2 Jun 2003 06:44:41 +0200
attribute node in xslt
"Adrian Grigore" <adrian@xxxxxxxxxxxxxxx> wrote in message
news:5.1.1.6.0.20030601225755.00bdfe18@xxxxxxxxxxxxxxxxxx
> Hi,
>
> I am currently working with xsl-metaprogramming (an xsl template is
> compiling another language into xsl) and need to generate a template that
> behaves differently when it's current node is an attribute node than when
> it's current node is any other kind of node.
>
> In other words, I am looking for an easy way to check within the
> template  example if the template's match attribute is something like
>
> /somenode/@id
>
> in which case it matched an attribute node or something like
>
> /somenode/somechildnode
>
> in which case it matched a element node.

This problem is rather artificial -- you can just have two templates -- one
matching elements and one matching attributes. In this way you do not have
to code anything in order to determine the type of node -- the XSLT
processor does this for you. If the template matching attributes is
instantiated, this means that the current node is an attribute.

If due to some (difficult to justify) reasons you have decided to process
both elements and attributes (and other types of nodes excluding only
namespace nodes, which cannot be matched) within a single template, then the
way to determine the type of node is as follows:

    -  element node
       self::*

   - comment node
     self::comment()

  - processing instruction node
    self::processing-instruction()

 - text node
   self::text()

 - root node
   not(..)

 - attribute node
   count(. | ../@*) = count(../@*)

OR

 count(. | ../@*[name() = name(current())]) = 1

OR

  using variations of the above with generate-id()

 - namespace node
  count(. | ../namespace::*) =  count(../namespace::*)


You may find these expressions used in a snippet that builds one of the many
possible XPath expressions that select a specific node:

http://www.topxml.com/code/default.asp?p=3&id=v20010323001030



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




 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.