Discussion:
Unable to use count function because of Namespaces...
Yaswanth
2007-09-07 11:30:17 UTC
Permalink
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"
xmlns:cbe="http://www.readiminds.com/schema/cbe"
xmlns:sb="http://www.readiminds.com/infra/readione/workbench/signaturebuilde
r" xmlns:xmi="http://www.omg.org/XMI">
<every>
<every>
<event alias="Event1" name="FraudEvent"/>
</every>
<every>
<event alias="Event1" name="FraudEvent"/>
</every>
</every>
<every>
</every>
</sb:Signature>
----------------

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)"/>

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

What should be my xsl to find no of EVERY's in sb:Signature..?
<xsl:variable name="cevery" select="count(??????????)"/>
I am expecting output as 2..


Can any one please help on this ?




Thanks & Regards,
Yaswanth Kumar Ravella



--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
David Carlisle
2007-09-07 11:35:02 UTC
Permalink
Post by Yaswanth
says prefix should resolve to name space !!
you need to declare the prefix in your xslt (it doesn't have to be the
same prefix but does need to be the same uri) so add

xmlns:sb="http://www.readiminds.com/infra/readione/workbench/signaturebuilder"

to your xsl:stylesheet. this is nothing to do with the count() function,
just a basic XPath requirement that to select an eleemnt in a namespace
the namespace needs to be known to the stylesheet.

David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs.
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Yaswanth
2007-09-07 11:40:30 UTC
Permalink
Hi David,
Thanks for the solution .
My problem is solved,
I changed my style sheet like this .. '

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sb="http://www.readiminds.com/infra/readione/workbench/signaturebuilde
r">

Thanks,


Thanks & Regards,
Yaswanth Kumar Ravella

-----Original Message-----
From: David Carlisle [mailto:***@nag.co.uk]
Sent: Friday, September 07, 2007 5:05 PM
To: xsl-***@lists.mulberrytech.com
Subject: Re: [xsl] Unable to use count function because of Namespaces...
Post by Yaswanth
says prefix should resolve to name space !!
you need to declare the prefix in your xslt (it doesn't have to be the
same prefix but does need to be the same uri) so add

xmlns:sb="http://www.readiminds.com/infra/readione/workbench/signaturebuilde
r"

to your xsl:stylesheet. this is nothing to do with the count() function,
just a basic XPath requirement that to select an eleemnt in a namespace
the namespace needs to be known to the stylesheet.

David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs.
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Abel Braaksma
2007-09-07 11:49:57 UTC
Permalink
Yaswanth, see below for some comments...
Post by Yaswanth
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"
xmlns:cbe="http://www.readiminds.com/schema/cbe"
xmlns:sb="http://www.readiminds.com/infra/readione/workbench/signaturebuilde
r" xmlns:xmi="http://www.omg.org/XMI">
<every>
<every>
<event alias="Event1" name="FraudEvent"/>
</every>
<every>
<event alias="Event1" name="FraudEvent"/>
</every>
</every>
<every>
</every>
</sb:Signature>
----------------
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).
Post by Yaswanth
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


--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--

Loading...