Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XQuery : Filter out duplicates [modified]

XQuery : Filter out duplicates [modified]

Scheduled Pinned Locked Moved XML / XSL
tutorialquestiondatabasecomxml
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DIMPLE_R
    wrote on last edited by
    #1

    I have an XML file which stores information of authors and books written by them. The following XQuery returns me a list of authors:- { for $b in doc("http://www.bn.com/bib.xml")//author return } However the resultset returned is:- - (since there could be more than 1 book written by an author) How do I change the above query to filter out duplicates? I saw a few sites which suggested using 'intersect'.I also came across the distinct-values function But I do not know how to use it in this example. Pls suggest:~ -- modified at 7:47 Thursday 13th July, 2006

    D 1 Reply Last reply
    0
    • D DIMPLE_R

      I have an XML file which stores information of authors and books written by them. The following XQuery returns me a list of authors:- { for $b in doc("http://www.bn.com/bib.xml")//author return } However the resultset returned is:- - (since there could be more than 1 book written by an author) How do I change the above query to filter out duplicates? I saw a few sites which suggested using 'intersect'.I also came across the distinct-values function But I do not know how to use it in this example. Pls suggest:~ -- modified at 7:47 Thursday 13th July, 2006

      D Offline
      D Offline
      DIMPLE_R
      wrote on last edited by
      #2

      Got it with "distinct-values" :) { let $a := doc("http://www.bn.com/bib.xml")//author for $last in distinct-values($a/last), $first in distinct-values($a[last=$last]/first) return {$last}{$first} }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups