[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] Re: Finding out if the current node is an attribute node
Subject: [xsl] 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 |
"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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Finding out if the curren, G. Ken Holman | Thread | RE: [xsl] conversion of time and/or, Michael Kay |
[xsl] Adding a node in sequence, John Reid | Date | RE: [xsl] Adding a node in sequence, Jarno . Elovirta |
Month |