XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
+ XSLT Help and Discussion (7625)
- XQuery Help and Discussion (2017)
-> + Issue with Processing Instruct... (2)
-> + problem converting json to XML... (2)
-> + Problem base64 decoding string... (3)
-> + Problems posting multipart for... (5)
-> + trouble with download of price... (2)
-> + Problem with http-post not bei... (3)
-> + path problem, xps_file:writeAl... (9)
-> + Xquery update support? (2)
-> + problem with Stylus studio try... (5)
-> + adding dtd reference to xml ou... (4)
-> + xquery escaping ambarsand when... (3)
-> + Whitespace problem when return... (5)
-> + Problem with namespace prefix ... (5)
-> - Sending via SFTP returns unexp... (1)
-> + Query and Sftp clent (4)
-> + xquery and try - catch (3)
-> + Query + ddtek:http-post optio... (5)
-> + Example files referenced in do... (3)
-> + Automatic Error Detection and ... (3)
-> + Working with result of ddtek:h... (2)
-- [1-20] [21-40] [41-60] Next
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
David LeeSubject: XQuery or XPath "between" function ... how to write ?
Author: David Lee
Date: 17 Oct 2006 05:27 PM
I'm trying to write an XQuery function that returns a subset of an item list "between" two items, identified by a condition ...
The goal is to take something like this

let $list := ("a","bunch","of","<tag>","words","with","markup","</tag>","in","a","list")

and call some function or xpath expression given "tag" or even better yet a regex pair like "<[a-z]+>" , "</[a-z]+>" and have it return
("<tag>","words","with","markup", "</tag>")
or even better
("words","with","markup")


The ultimate goal is to take a list of tokenized strings and dynamically an element based on text markup ... but even having something primative like

fn:between( $n as item()* , $first as item() , $last as item() ) as item()*


Suggestions greatly welcome !



I have no problems locating the first and last nodes, I'm just getting stuck generating the list of nodes between them (ideally exclusive of them)


Postnext
David LeeSubject: XQuery or XPath
Author: David Lee
Date: 17 Oct 2006 07:24 PM
I firgured this out finally ... took a while (XQuery is FUN ... but alas not so easy until you know how ... like everything else :)

declare function local:between( $list as node()* , $first as node() , $last as node() ) as node()*
{
$list[ . >> $first ][ . << $last ]
};


I also had a similar more complex one that worked too:

declare function local:between( $list as node()* , $first as node() , $last as node() ) as node()*
{
for $n in $list
where (($n >> $first) and ($n << $last ))
return $n/text()
};


Any comments on these ? They "appear to work" ... but are they correct ? Any reason to pick one over the other ? My guess is the first one is more efficient ... but who knows ...

Postnext
Ivan PedruzziSubject: XQuery or XPath
Author: Ivan Pedruzzi
Date: 18 Oct 2006 10:47 PM
Hi David,

Is your input well formed markup or a string?
Are you assuming to extract only one sub-region?

Here a simple solution that builds a list of begin/end pairs

declare variable $list := ("a","bunch","of","<tag>","words","with","markup","</tag>","in","a","list");
declare variable $indexes :=
for $item at $pos in $list
return
if(contains($item , "<tag>")) then $pos
else if(contains($item , "</tag>")) then $pos
else ();

for $i at $pos in $indexes[position() mod 2 = 1]
return subsequence($list, $i, $indexes[$pos + 1] - $i + 1)



Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Posttop
David LeeSubject: XQuery or XPath
Author: David Lee
Date: 19 Oct 2006 11:19 AM
Thanks, this helps a lot.
I was struggling trying to create a function that created a list which contains sub-lists which is not really possible (without constructing dummy node variabls) ... like ((1,2),(3,4)) is really (1,2,3,4)
but I hadnt thought of using "mod" ... thats useful !

Thank you

-David

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.