xsl-list
[Top] [All Lists]

[xsl] How to count the distinct values where elements with missing child are counted as one of the distinct values?

2022-05-26 09:08:43
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? 

/Roger
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--


<Prev in Thread] Current Thread [Next in Thread>