Re: [xsl] Unable to use count function because of Namespaces...

Subject: Re: [xsl] Unable to use count function because of Namespaces...
From: Abel Braaksma <>
Date: Fri, 07 Sep 2007 13:49:57 +0200
Yaswanth, see below for some comments...

Yaswanth wrote:
Hi All, I am facing a problem for counting ... because of namespaces.

I have my XML as ...
<?xml version="1.0" encoding="ISO-8859-1"?>
<sb:Signature xmi:version="2.0"
r" xmlns:xmi="";>	
		<event alias="Event1" name="FraudEvent"/>	
		<event alias="Event1" name="FraudEvent"/>	

And in my XSL

I want to count how many every's are there under <sb:Signature>
<xsl:variable name="cevery" select="count(//sb:Signature/every)"/>

I recommend using count(/sb:Signature.every) instead. sb:Signature is at your root, no reason to ask for the processor to search through every level at every depth (which is what // does) of the tree for a possible sb:Signature.

If you define "under sb:Signature" as under that nod at any depth, you have to put the // elsewhere, like this: count(/sb:Signature//every).

Now, since we know that sb:Signature is at the root level and since we know that a document can only have one root element (I know, this is not entirely true, for the sake of this discussion it suffices), we can change this requirement to: count(//every), which will count every node in your document.

As a result, you do not need to bind the prefix anymore because you are not searching for elements that are inside a namespace (you do not declare a default namespace in your snippet above).

This is not working .. It says prefix should resolve to name space !!

this has already been answered by David ;) but now it is not needed anymore (but of course, good practice learns us that it is best to copy the namespaces we have in the source(s) to the XSLT we are making.

Cheers, -- Abel Braaksma

Current Thread