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
jake feederSubject: getting all nodes leading up to a given node but no descendants...
Author: jake feeder
Date: 06 Mar 2007 03:23 PM
i feel like this should be easier than i'm making it... i have a document with recursively nested "tag" nodes as listed below.

what i want to do is get the tag with id=3, and all of its ancestors, but no other nodes. (would return <tag id="1" name="a"><tag id="2" name="b"><tag id="3" name="c"></tag></tag></tag>)

i've got:

//tag[@id="3"]/ancestor-or-self::node()

which gives me the proper nodes, and i could use a loop to recreate the tag structure, but i feel like i'm missing something trivial, probably a simple xpath solution with no need for loops at all.

does anyone else see the obvious solution that is eluding me, or do i really need to loop through and recreate the tags?

thanks,

--jake

<tag id="1" name="a">
<tag id="2" name="b">
<tag id="3" name="c">
<tag id="4" name="d">
</tag>
</tag>
<tag id="5" name="x">
</tag>
</tag>
</tag>
<tag id="6" name="y">
</tag>
<tag id="7" name="z">
</tag>


Postnext
(Deleted User) Subject: getting all nodes leading up to a given node but no descendants...
Author: (Deleted User)
Date: 07 Mar 2007 03:17 AM
Hi Jake,
your solution is the correct one; every XPath expression will simply select one or more existing nodes from the input tree, while you want to create a new structure that only contains some of the them. So you have to extract the <tag> nodes you are interested into, and build copies of them excluding the children and attributes you are not interested into.

Alberto

Posttop
jake feederSubject: getting all nodes leading up to a given node but no descendants...
Author: jake feeder
Date: 08 Mar 2007 01:29 PM
Thanks for the confirmation Alberto.

In case anyone else needs this someday, here is the recursive function I ended up with for this..

define function LimitPathToChildren($nTags, $iID)
{
for $nTag in $nTags
return
if ($nTag//@tagid=$iID) then
element { node-name($nTag)}
{ $nTag/@*, LimitPathToChildren($nTag/tag,$iID) }
else ()
}

for $nTag in $nTags
return LimitPathToChildren($nTag, (271,133,134))

--jake

   
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.