xsl-list
[Top] [All Lists]

[xsl] XQuery - Two if's in a for loop

2011-04-17 15:36:17
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>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>