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
Postnext
sebastien vinchonSubject: Looking for xQuery help
Author: sebastien vinchon
Date: 18 Sep 2008 01:04 PM
Can anybody help me on the needed xQuery to do the transformation illustrated by the two attached files?


UnknownPOL_Modified_xQueryInput.xml
Input

UnknownPOL_Modified_xQueryExpectedResult.xml
Output

Postnext
Minollo I.Subject: Looking for xQuery help
Author: Minollo I.
Date: 18 Sep 2008 01:32 PM
Something like this:

declare option ddtek:serialize "indent=yes";

declare function local:getFields($item) {
let $nextItem := $item/following-sibling::*[local-name()!="FieldAndValuesPairs"][1]
for $field in $item/following-sibling::*[local-name()="FieldAndValuesPairs"]
where if($nextItem) then $field << $nextItem else true()
return $field
};

<Documents> {
for $Template in /root/Template
return
<Document>
<TemplateName>{$Template/TemplateName/text()}</TemplateName>
{
for $field in local:getFields($Template)
return
element {$field/*/local-name()} {$field/*/text()}
}
</Document>
} </Documents>

Postnext
sebastien vinchonSubject: Looking for xQuery help
Author: sebastien vinchon
Date: 18 Sep 2008 08:19 PM
Thank you for the feedback but I had already been able to obtain such a result using the code below.

My problem is actually to be able to nest the "Document" nodes whose template name does not start with "MPOL" as "SubDocument" nodes below the preceding MPOL.

This is shown by the "ExpectResult" XML I provided initially if you look at it in details

Here is my current xquery code (that does not do the needed nesting):

declare option ddtek:serialize "indent=yes";

declare function local:getRelatedRecords($item) {
let $nextItem := $item/following-sibling::*[local-name()="Template"][1]
for $related in $item/following-sibling::*[local-name()!="Template"]
where if($nextItem) then $related << $nextItem else true()
return $related
};

<Documents>
{
for $Template in /root/Template
return
<Document>
{$Template/*}
{
for $NOT_Template in local:getRelatedRecords($Template)
return
$NOT_Template/*
}
</Document>
}
</Documents>

Postnext
sebastien vinchonSubject: Looking for xQuery help
Author: sebastien vinchon
Date: 18 Sep 2008 08:21 PM
If you look at "POL_Modified_xQueryExpectedResult.xml", you'll notice that it contains only 2 "Document" nodes (and not 8) and that each ot them has 3 "SubDocument" nodes.

Postnext
Minollo I.Subject: Looking for xQuery help
Author: Minollo I.
Date: 18 Sep 2008 09:04 PM
Same concept:

declare option ddtek:serialize "indent=yes";

declare function local:getSubDocuments($item) {
let $nextItem := $item/following-sibling::*[local-name()="Template" and starts-with(TemplateName,"MPOL")][1]
for $field in $item/following-sibling::*[local-name()="Template"]
where if($nextItem) then $field << $nextItem else true()
return $field
};
declare function local:getFields($item) {
let $nextItem := $item/following-sibling::*[local-name()!="FieldAndValuesPairs"][1]
for $field in $item/following-sibling::*[local-name()="FieldAndValuesPairs"]
where if($nextItem) then $field << $nextItem else true()
return $field
};

<Documents> {
for $Template in /root/Template[starts-with(TemplateName,"MPOL")]
return
<Document>
<TemplateName>{$Template/TemplateName/text()}</TemplateName>
{
for $field in local:getFields($Template)
return
element {$field/*/local-name()} {$field/*/text()},
for $subDocument in local:getSubDocuments($Template)
return
<SubDocument>
<TemplateName>{$subDocument/TemplateName/text()}</TemplateName>
{
for $field in local:getFields($subDocument)
return
element {$field/*/local-name()} {$field/*/text()}
}
</SubDocument>
}
</Document>
} </Documents>

Posttop
sebastien vinchonSubject: Looking for xQuery help
Author: sebastien vinchon
Date: 19 Sep 2008 05:15 AM
You guys are great! It works just fine!

 
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!  
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.