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

Re: How to count the distinct values where elements wi

Subject: Re: How to count the distinct values where elements with missing child are counted as one of the distinct values?
From: "Mukul Gandhi mukulg@xxxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 27 May 2022 05:27:33 -0000
Re:  How to count the distinct values where elements wi
Hi Roger,
    How about below mentioned solution, for your requirements.

XML document : provided XML document

XSLT stylesheet,

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                         version="3.0">

   <xsl:output method="text"/>

   <xsl:template match="/">
      <xsl:value-of select="count(distinct-values(test/row/transition)) +
                                                        (if (some $row in
test/row satisfies not($row/transition)) then 1 else 0)"/>
   </xsl:template>

</xsl:stylesheet>

On Thu, May 26, 2022 at 7:38 PM Roger L Costello costello@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Hi Folks,
>
> The following XML document has two row elements with no transition element
> and two row elements with a transition element :
>
> <test>
>     <row>
>     </row>
>     <row>
>     </row>
>     <row>
>         <transition>ABC</transition>
>     </row>
>     <row>
>         <transition>DEF</transition>
>     </row>
> </test>
>
> I want a count of the number of distinct transition values, where row
> elements with no transition element are counted as 1.
>
> So for the above XML document the count should return 3.
>
> This XPath seems to work:
>
> count(distinct-values(/test/row/transition)) +
> count(/test/row[not(transition)][1])
>
> But I am wondering if there is a better (simpler, less kludgy) XPath
> expression?
>


-- 
Regards,
Mukul Gandhi

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.