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
Priti VermaSubject: Xquery ques. How to check for empty attributes
Author: Priti Verma
Date: 26 Apr 2004 02:23 PM
An XQuery ques:

I have a following XML doc

<Loan LoanId="123" InterestRate="5.9"/>
<Loan LoanId="" InterestRate="6.0"/>

I need an XQuery solution that creates Loan records without the
LoanId attribute, when LoanId attribute is blank.

<Loan Id="123" Int="5.9"/>
<Loan Int="6.0"/>

Posttop
Minollo I.Subject: Re: Xquery ques. How to check for empty attributes
Author: Minollo I.
Date: 26 Apr 2004 04:10 PM
One way to do that is:

<Loans>
{
for $Loan in /Loans/Loan
return
if($Loan/@LoanId and string-length($Loan/@LoanId)>0) then
<Loan Int="{$Loan/@InterestRate}" Id="{$Loan/@LoanId}"/>
else
<Loan Int="{$Loan/@InterestRate}"/>
}
</Loans>

...which will work fine in Stylus 173i and its mapper.

A much cleaner solution would probably be:

<Loans>
{
for $Loan in /Loans/Loan
return
<Loan Int="{$Loan/@InterestRate}">
{
if($Loan/@LoanId and string-length($Loan/@LoanId)>0) then
(attribute Id {$Loan/@LoanId})
else ()
}
</Loan>
}
</Loans>

...this will work fine in BL173i if you manually edit/run it, but it won't
work in XQuery mapper; we are working to address this issue.

Minollo

 
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.