Hi,
Just a trivial question on XQuery. I've got the following result set from the p:query process: <result> <node label="General literary works (e.g., fiction, plays)"/> <node label="General systems theory"/> <node label="General literary works (e.g., fiction, plays)"/> <node label="General"/> <node label="General"/> <node label="General systems theory"/> <node label="Representations (general and polynomial)"/> </result> And would like to have a distinct results: <result> <node label="General literary works (e.g., fiction, plays)"/> <node label="General systems theory"/> <node label="General"/> <node label="Representations (general and polynomial)"/> </result> Do you know how this may be accomplish in XQuery? The XQuery that produce the original results is: xquery version "1.0"; <result> {//node[contains(@label,'General')]} </result> I tried the distinct-values(): xquery version "1.0"; <result> { distinct-values(//node[contains(@label,'General')]/@label)} </result> But only get this get me this: <result>General literary works (e.g., fiction, plays) General systems theory Representations (general and polynomial) General</result> Would be required is a "distinct-nodes" function.. but this is not supported yet? Any pointers would be much appreciated. Regards, Boon ----- Boon Low System Developer, EGEE Training UK National e-Science Centre http://homepages.ed.ac.uk/boon -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Maybe you could use distinct-nodes (xpath 2.0), but using a different
XSLT processor? Are you using oxf:xslt? Or one of the others? If you have a look at http://www.orbeon.com/ops/doc/processors-xslt#d114768e193 you'll see there is a whole variety of XSLT processors, I would have thought that one of these would support distinct-nodes. Otherwise you could plug in a completely different XSLT engine (maybe call as a web service). Steve -----Original Message----- From: Boon Low [mailto:[hidden email]] Sent: 06 September 2005 14:23 To: [hidden email] Subject: [ops-users] XQuery question Hi, Just a trivial question on XQuery. I've got the following result set from the p:query process: <result> <node label="General literary works (e.g., fiction, plays)"/> <node label="General systems theory"/> <node label="General literary works (e.g., fiction, plays)"/> <node label="General"/> <node label="General"/> <node label="General systems theory"/> <node label="Representations (general and polynomial)"/> </result> And would like to have a distinct results: <result> <node label="General literary works (e.g., fiction, plays)"/> <node label="General systems theory"/> <node label="General"/> <node label="Representations (general and polynomial)"/> </result> Do you know how this may be accomplish in XQuery? The XQuery that produce the original results is: xquery version "1.0"; <result> {//node[contains(@label,'General')]} </result> I tried the distinct-values(): xquery version "1.0"; <result> { distinct-values(//node[contains(@label,'General')]/@label)} </result> But only get this get me this: <result>General literary works (e.g., fiction, plays) General systems theory Representations (general and polynomial) General</result> Would be required is a "distinct-nodes" function.. but this is not supported yet? Any pointers would be much appreciated. Regards, Boon ----- Boon Low System Developer, EGEE Training UK National e-Science Centre http://homepages.ed.ac.uk/boon -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
In reply to this post by Boon Low
Sorry misread! You're talking query rather than xslt, so this approach
wouldn't work, though you might be able to plug in an external processor which supports 2.0. -----Original Message----- From: Stephen Bayliss Sent: 06 September 2005 15:11 To: [hidden email] Subject: RE: [ops-users] XQuery question Maybe you could use distinct-nodes (xpath 2.0), but using a different XSLT processor? Are you using oxf:xslt? Or one of the others? If you have a look at http://www.orbeon.com/ops/doc/processors-xslt#d114768e193 you'll see there is a whole variety of XSLT processors, I would have thought that one of these would support distinct-nodes. Otherwise you could plug in a completely different XSLT engine (maybe call as a web service). Steve -----Original Message----- From: Boon Low [mailto:[hidden email]] Sent: 06 September 2005 14:23 To: [hidden email] Subject: [ops-users] XQuery question Hi, Just a trivial question on XQuery. I've got the following result set from the p:query process: <result> <node label="General literary works (e.g., fiction, plays)"/> <node label="General systems theory"/> <node label="General literary works (e.g., fiction, plays)"/> <node label="General"/> <node label="General"/> <node label="General systems theory"/> <node label="Representations (general and polynomial)"/> </result> And would like to have a distinct results: <result> <node label="General literary works (e.g., fiction, plays)"/> <node label="General systems theory"/> <node label="General"/> <node label="Representations (general and polynomial)"/> </result> Do you know how this may be accomplish in XQuery? The XQuery that produce the original results is: xquery version "1.0"; <result> {//node[contains(@label,'General')]} </result> I tried the distinct-values(): xquery version "1.0"; <result> { distinct-values(//node[contains(@label,'General')]/@label)} </result> But only get this get me this: <result>General literary works (e.g., fiction, plays) General systems theory Representations (general and polynomial) General</result> Would be required is a "distinct-nodes" function.. but this is not supported yet? Any pointers would be much appreciated. Regards, Boon ----- Boon Low System Developer, EGEE Training UK National e-Science Centre http://homepages.ed.ac.uk/boon -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
I am not an expert in XQuery, but you might try this:
<result> { for $dist in distinct-values(doc('input:test-xml')/result/node/@label) return <node label="{$dist}"/> } </result> where test-xml input refers to your input XML: <result> <node label="General literary works (e.g., fiction, plays)"/> <node label="General systems theory"/> <node label="General literary works (e.g., fiction, plays)"/> <node label="General"/> <node label="General"/> <node label="General systems theory"/> <node label="Representations (general and polynomial)"/> </result> A. On Sep 6, 2005, at 4:25 PM, Stephen Bayliss wrote: > Sorry misread! You're talking query rather than xslt, so this approach > wouldn't work, though you might be able to plug in an external > processor > which supports 2.0. > > -----Original Message----- > From: Stephen Bayliss > Sent: 06 September 2005 15:11 > To: [hidden email] > Subject: RE: [ops-users] XQuery question > > Maybe you could use distinct-nodes (xpath 2.0), but using a different > XSLT processor? Are you using oxf:xslt? Or one of the others? > > If you have a look at > http://www.orbeon.com/ops/doc/processors-xslt#d114768e193 you'll see > there is a whole variety of XSLT processors, I would have thought that > one of these would support distinct-nodes. > > Otherwise you could plug in a completely different XSLT engine (maybe > call as a web service). > > Steve > > -----Original Message----- > From: Boon Low [mailto:[hidden email]] > Sent: 06 September 2005 14:23 > To: [hidden email] > Subject: [ops-users] XQuery question > > Hi, > > Just a trivial question on XQuery. > > I've got the following result set from the p:query process: > > <result> > <node label="General literary works (e.g., fiction, plays)"/> > <node label="General systems theory"/> > <node label="General literary works (e.g., fiction, plays)"/> > <node label="General"/> > <node label="General"/> > <node label="General systems theory"/> > <node label="Representations (general and polynomial)"/> > </result> > > And would like to have a distinct results: > > <result> > <node label="General literary works (e.g., fiction, plays)"/> > <node label="General systems theory"/> > <node label="General"/> > <node label="Representations (general and polynomial)"/> > </result> > > Do you know how this may be accomplish in XQuery? > > The XQuery that produce the original results is: > > xquery version "1.0"; > <result> > {//node[contains(@label,'General')]} > </result> > > I tried the distinct-values(): > > xquery version "1.0"; > <result> > { distinct-values(//node[contains(@label,'General')]/@label)} > </result> > > But only get this get me this: > > <result>General literary works (e.g., fiction, plays) General systems > theory Representations (general and polynomial) General</result> > > Would be required is a "distinct-nodes" function.. but this is not > supported yet? > > Any pointers would be much appreciated. > > Regards, > > Boon > > ----- > Boon Low > System Developer, EGEE Training > UK National e-Science Centre > http://homepages.ed.ac.uk/boon > > > -- > You receive this message as a subscriber of the > [hidden email] mailing list. > To unsubscribe: mailto:[hidden email] > For general help: mailto:[hidden email]?subject=help > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
In reply to this post by Boon Low
On Tue, 6 Sep 2005 14:22:57 +0100, "Boon Low" <[hidden email]> said: > Hi, > > Just a trivial question on XQuery. > > I've got the following result set from the p:query process: > > <result> > <node label="General literary works (e.g., fiction, plays)"/> > <node label="General systems theory"/> > <node label="General literary works (e.g., fiction, plays)"/> > <node label="General"/> > <node label="General"/> > <node label="General systems theory"/> > <node label="Representations (general and polynomial)"/> > </result> > > And would like to have a distinct results: > > <result> > <node label="General literary works (e.g., fiction, plays)"/> > <node label="General systems theory"/> > <node label="General"/> > <node label="Representations (general and polynomial)"/> > </result> > > Do you know how this may be accomplish in XQuery? > > The XQuery that produce the original results is: > > xquery version "1.0"; > <result> > {//node[contains(@label,'General')]} > </result> > > I tried the distinct-values(): > > xquery version "1.0"; > <result> > { distinct-values(//node[contains(@label,'General')]/@label)} > </result> > > But only get this get me this: > > <result>General literary works (e.g., fiction, plays) General systems > theory Representations (general and polynomial) General</result> > > Would be required is a "distinct-nodes" function.. but this is not > supported yet? > > Any pointers would be much appreciated. > <result> {for $p in distinct-values(/stuff/node/@label) return /stuff/node[ @label eq $p ][ 1 ] } </result> However I am pretty sure it won't scale all that well. Unfortuantely I am more of a Java/C++ programmer, so I don't know off the top my head what a more scalable solution would look like in XQuery. ( Perhaps a recursive function with a variable containing the visited node label values? ) -- Regards, Dan S -- http://www.fastmail.fm - Accessible with your email software or over the web -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Hi,
Many thanks for all your tips. It is just what we required.. and another good lesson on XML. Nice to see the combined benefits of XQuery and XPath functions. I noticed that the distinct-nodes() used to be in Saxon 7.7, but it's no longer in latest Saxon 8.X release? Boon On 6 Sep 2005, at 21:43, [hidden email] wrote: > > On Tue, 6 Sep 2005 14:22:57 +0100, "Boon Low" <[hidden email]> > said: > > > >> Hi, >> >> Just a trivial question on XQuery. >> >> I've got the following result set from the p:query process: >> >> <result> >> <node label="General literary works (e.g., fiction, plays)"/> >> <node label="General systems theory"/> >> <node label="General literary works (e.g., fiction, plays)"/> >> <node label="General"/> >> <node label="General"/> >> <node label="General systems theory"/> >> <node label="Representations (general and polynomial)"/> >> </result> >> >> And would like to have a distinct results: >> >> <result> >> <node label="General literary works (e.g., fiction, plays)"/> >> <node label="General systems theory"/> >> <node label="General"/> >> <node label="Representations (general and polynomial)"/> >> </result> >> >> Do you know how this may be accomplish in XQuery? >> >> The XQuery that produce the original results is: >> >> xquery version "1.0"; >> <result> >> {//node[contains(@label,'General')]} >> </result> >> >> I tried the distinct-values(): >> >> xquery version "1.0"; >> <result> >> { distinct-values(//node[contains(@label,'General')]/@label)} >> </result> >> >> But only get this get me this: >> >> <result>General literary works (e.g., fiction, plays) General systems >> theory Representations (general and polynomial) General</result> >> >> Would be required is a "distinct-nodes" function.. but this is not >> supported yet? >> >> Any pointers would be much appreciated. >> >> >> >> > > This seems to work > > <result> > {for $p in distinct-values(/stuff/node/@label) > return /stuff/node[ @label eq $p ][ 1 ] > } > </result> > > > However I am pretty sure it won't scale all that well. Unfortuantely > I am more of a Java/C++ programmer, so I don't know off the top my > head > what a more scalable solution would look like in XQuery. ( Perhaps > a recursive function with a variable containing the visited node > label values? ) > > -- Regards, Dan S > > -- > http://www.fastmail.fm - Accessible with your email software > or over the web > > > > -- > You receive this message as a subscriber of the ops- > [hidden email] mailing list. > To unsubscribe: mailto:[hidden email] > For general help: mailto:[hidden email]?subject=help > ObjectWeb mailing lists service home page: http://www.objectweb.org/ > wws > > > ----- Boon Low System Developer, EGEE Training UK National e-Science Centre http://homepages.ed.ac.uk/boon -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
Boon Low wrote:
> Hi, > > Many thanks for all your tips. It is just what we required.. and > another good lesson on XML. Nice to see the combined benefits of XQuery > and XPath functions. I noticed that the distinct-nodes() used to be in > Saxon 7.7, but it's no longer in latest Saxon 8.X release? I see that distinct-nodes() has been removed between the drafts of 2 May 2003 and 12 November 2003. I do not know the reationale. However, the current draft shows how you can implement that function: http://www.w3.org/TR/xpath-functions/#func-distinct-nodes-stable -Erik -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Free forum by Nabble | Edit this page |