Hi,
I have a requirement, where in i have to get distinct values from an xml file.
EX: Input
Required output: StringCode:<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Main xmlns="http://www.abc.org.com/FormDetails"> <abcd first="1" second="2"/> <Fruits> <fruit name="banana" color="green"> <fruit name="apple" color="red"> <fruit name="grape" color="green"> <fruit name="apple" color="red"> <fruit name="banana" color="green"> <fruit name="apple" color="red"> <fruit name="grape" color="green"> <fruit name="orange" color="orange"> <fruit name ="lemon" color="yellow"> </Fruits> <Fruits> <fruit name="banana" color="green"> <fruit name="apple" color="red"> <fruit name="grape" color="green"> <fruit name="apple" color="red"> <fruit name="banana" color="green"> <fruit name="apple" color="red"> <fruit name="grape" color="green"> <fruit name="orange" color="orange"> <fruit name ="lemon" color="yellow"> </Fruits> <Fruits> <fruit name="banana" color="green"> <fruit name="apple" color="red"> <fruit name="grape" color="green"> <fruit name="apple" color="red"> <fruit name="banana" color="green"> <fruit name="apple" color="red"> <fruit name="grape" color="green"> <fruit name="orange" color="orange"> <fruit name ="lemon" color="yellow"> </Fruits> </Main>
banana = green|apple = red| grape=green|orange=orange|lemon=yellow
I have used this xquery:I am getting error like:Code:declare namespace xf = "http://tempuri.org/abcorg/Transformations/Distinct_Fruits/"; declare namespace ns = "http://www.abc.org.com/FormDetails"; declare function xf:Distinct_Fruits($fruits as element(ns:Main)) as xs:string{ for $d in distinct-values($fruits//ns:fruit/@name) return "{$d} =" for $e in distinct-values($fruits//ns:fruit/@color) return "{$e}|" }; declare variable $fruitsas element(ns:Main) external; xf:Distinct_Member($fruits)
Error executing the XQuery transformation: line 11, column 1: {err}FORG0005: expected exactly one item, got 2+ items
Please let me know where It went wrong.
Thanks..


Reply With Quote



Bookmarks