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
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
First LastSubject: XQuery Replace
Author: First Last
Date: 16 Sep 2005 03:08 PM
I'm trying to create an xQuery that will let me replace a node (or nodes) that may or may not exist in an xml document. The purpose being I just want to know that they are there (not what it's in it for now).

Here's the xml:
<object id="1">
<option att="a">A</option>
<option att="b">B</option>
<object id="2"/>

Here's what I want returned from the xquery:
<object id="1">
<object id="2"/>

Much appreciation to anyone that can help me with this xQuery.

Alberto MassariSubject: XQuery Replace
Author: Alberto Massari
Date: 19 Sep 2005 03:51 AM
Hi Joel,
this simple query will work, assuming the structure of the input file is the one of your sample (i.e. "option" is the only node that can appear under "object"):

for $node in /stuff/object
<object id="{$node/@id}">
for $option in $node/option
return <option/>

Hope this helps,

Go to previous topicPrev TopicGo to next topicNext Topic
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!  

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.