Re: [xsl] How to find out number of elements which does not have a particular attribute

Subject: Re: [xsl] How to find out number of elements which does not have a particular attribute
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 07 Jul 2004 11:50:26 -0400
Ranjan,

But I'm not sure this is going to work (have you tested it?):

count(connectivity//*[@*[not(local-name() = 'sharedsource')]])

for the stated requirement

how to find out [the] number of elments which [do] not have a particular attribute?

Parsing the XPath into English ...


count()
  counts a set of nodes

connectivity
expands to child::connectivity ('connectivity' child elements of the context node) ... this could be what you want, depending on the input and the context node being matched


connectivity//*
  expands to child::connectivity/descendant-or-self::node()/*
  namely any element descendant of the 'connectivity' children

[@*]
  "which has an attribute"

[not(local-name() = 'sharedsource')]
  "whose local name is not 'sharedsource'"

In other words, the expression returns the count of all descendants of 'connectivity' children that have an attribute whose local name is not 'sharedsource'.

This is different from all elements that have no 'sharedsource' attribute.

To cut to the chase, the latter would be

count(//*[not(@sharedsource)])

which returns the count of all element descendants of the root that have no 'sharedsource' attribute.

Its long-syntax form is

count(/descendant-or-self::node()/*[not(attribute::sharedsource)])

Cheers,
Wendell

At 08:36 AM 7/7/2004, 'twas written:
> <xsl:variable name="sharedcount1"
> select="count(connectivity//*[@*[not(local-name() =
> 'sharedsource')]])"/>


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