0
votes

I've got a simple XML file for testing:

<?xml version="1.0" encoding="UTF-8"?>
<A>
    <B >1</B>
    <B >2</B>
    <B >3</B>
    <B >2</B>
    <B >4</B>
    <B >5</B>
    <B >3</B>
</A>

And I'm trying out some XPATH 2.0 functions in the XPATH console in Eclipse (Juno). I can't seem to get the following to run:

distinct-values(/A/B/text())

I think that the result should be the numbers 1-5. Instead, I get

1
2
3
2
4
5
3

Can anyone else confirm this? I tried with Saxon 9.4 as the XSLT 2.0 processor, again in Eclipse. Tried with PsychoPath too.

Do i have a misunderstanding of distinct-values()? I thought in XSLT 2.0 it would take a sequence of atomic data or a set of nodes and spit out the unique items.

Thx.

2
I think the problem must be with the Eclipse/Juno environment. Saxon itself has no problems with this.Michael Kay

2 Answers

0
votes

I can assure you that Saxon supports the distinct-values function, it works fine for me with Saxon 9.5 HE Java run from the command line (using XQuery instead of XPath as there is no command line interface for pure XPath 2.0 but that should not matter to test a simpe function call). So when using

'C:\Program Files (x86)\Java\jre7\bin\java.exe' -cp 'C:\Program Files (x86)\Saxonica\SaxonHE9.5J\saxon9he.jar' net.sf.saxon.Query -s:test2013061801.xml '-qs:distinct-values(/A/B)'

at a Powershell command line prompt on Windows 8 where the contents of the input XML test2013061801.xml is your file

<?xml version="1.0" encoding="UTF-8"?>
<A>
    <B >1</B>
    <B >2</B>
    <B >3</B>
    <B >2</B>
    <B >4</B>
    <B >5</B>
    <B >3</B>
</A>

Saxon outputs <?xml version="1.0" encoding="UTF-8"?>1 2 3 4 5.

I don't know how Saxon integrates in Eclipse or what PsychoPath is but with Saxon or any other XPath 2.0 or XQuery 1.0 you shouldn't have any problem with that path expression returning distinct values.

0
votes

Yes distinct-value function work fine and you can find correct result from below mention code:

<xsl:template match="A">
<xsl:for-each select="distinct-values(child::B)">
<xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</xsl:template>