[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XQuery - Two if's in a for loop

Subject: Re: XQuery - Two if's in a for loop
From: sudheshna iyer <sudheshnaiyer@xxxxxxxxx>
Date: Mon, 18 Apr 2011 01:41:28 -0700 (PDT)
Re:  XQuery - Two if's in a for loop
In other words, I want something like below. Please note that these are not
else 
if. It is working if i put else if. But I want all the blocks..not just
one or 
two or three..

If (ReturnParameterCode = One) then block one should
be present
If (ReturnParameterCode = two) then block two should be present
If
(ReturnParameterCode = three) then block three should be present

So if input
is 
<tns:InputMSG1>
 <tns:CustNum>111</tns:CustNum>
 <tns:ReturnParameter>
  <tns:ReturnParameterCode>ONE</tns:ReturnParameterCode>
  <tns:ReturnParameterCode>TWO</tns:ReturnParameterCode>
  <tns:ReturnParameterCode>THREE</tns:ReturnParameterCode>
 </tns:ReturnParameter>
</tns:InputMSG1>
Output should be: 
<tns:OutputMSG1>
 <tns:ONE>
  <tns:Id>String</tns:Id>
  <tns:Number>String</tns:Number>
 </tns:ONE>
 <tns:TWO>
  <tns:Id>String</tns:Id>
  <tns:Number>String</tns:Number>
 </tns:TWO>
 <tns:THREE>
  <tns:Id>String</tns:Id>
  <tns:Number>String</tns:Number>
 </tns:THREE> 
</tns:OutputMSG1>



----- Original Message ----
From: sudheshna iyer
<sudheshnaiyer@xxxxxxxxx>
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Sent: Sun, April
17, 2011 4:36:04 PM
Subject:  XQuery - Two if's in a for loop

Can I have
multiple if's in a for loop?
I have input xml. I need to do XQuery
transformation to form output xml based on 

occurance of elements in input
xml 

Input xml: 
<?xml version="1.0" encoding="UTF-8"?>
<tns:InputMSG1
xsi:schemaLocation="http://xmlns.aaa.com InputMSG.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns2="http://xmlns.aaa.org" xmlns:tns="http://xmlns.aaa.org">
 <tns:CustNum>111</tns:CustNum>
 <tns:ReturnParameter>
  <tns:ReturnParameterCode>ONE</tns:ReturnParameterCode>
  <tns:ReturnParameterCode>TWO</tns:ReturnParameterCode>
 </tns:ReturnParameter>
</tns:InputMSG1>

If ReturnParameterCode is "ONE",
then block <ONE> should appear in the output
if ReturnParameterCode = TWO is
present then block <TWO> should appear. 

My output should be: 
<?xml
version="1.0" encoding="UTF-8"?>
<tns:OutputMSG1
xsi:schemaLocation="http://xmlns.aaa.com InputMSG.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns2="http://xmlns.aaa.org" xmlns:tns="http://xmlns.aaa.com">
 <tns:ONE>
  <tns:Id>String</tns:Id>
  <tns:Number>String</tns:Number>
 </tns:ONE>  
 <tns:TWO>
  <tns:Name>String</tns:Name>
 </tns:TWO>
</tns:OutputMSG1>

IF
input xml doesn't have 
<tns:ReturnParameterCode>TWO</tns:ReturnParameterCode>, block <TWO> shouldn't
appear in the output. 

<?xml version="1.0" encoding="UTF-8"?>
<tns:InputMSG1
xsi:schemaLocation="http://xmlns.aaa.com InputMSG.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns2="http://xmlns.aaa.org" xmlns:tns="http://xmlns.aaa.org">
 <tns:CustNum>111</tns:CustNum>
 <tns:ReturnParameter>
  <tns:ReturnParameterCode>ONE</tns:ReturnParameterCode>
 </tns:ReturnParameter>
</tns:InputMSG1>
My output should be: 
<?xml
version="1.0" encoding="UTF-8"?>
<tns:OutputMSG1
xsi:schemaLocation="http://xmlns.aaa.com InputMSG.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns2="http://xmlns.aaa.org" xmlns:tns="http://xmlns.aaa.com">
 <tns:ONE>
  <tns:Id>String</tns:Id>
  <tns:Number>String</tns:Number>
 </tns:ONE>  
</tns:OutputMSG1>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.