distinct in Xpath?

后端 未结 6 819
走了就别回头了
走了就别回头了 2020-12-03 04:37

I have this XML file, from which I\'d like to count the number of users referenced in it. But they can appear in more than one category, and I\'d like these duplicates not t

6条回答
  •  北海茫月
    2020-12-03 05:06

    using the functions namespace http://www.w3.org/2005/xpath-functions you can use

    distinct-values(//list/group/user)
    

    UPDATE:

    At the top of your xsl/xslt file you should have a stylesheet element, map the url above to the prefix fn as below...

    
    

    then you can use

    select="fn:distinct-values(//list/group/user)"
    

    this would assume you are doing this in templates and not in some xpathdocument object inwhich case you need to use a namespacemanager class.

    links...

    XSLT: Add namespace to root element

    http://www.xqueryfunctions.com/xq/fn_distinct-values.html

    http://msdn.microsoft.com/en-us/library/d6730bwt(VS.80).aspx

    Otherwise try Dimitre Novatchev's answer.

提交回复
热议问题