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

urgent..creating loops in output xml based on input xm

Subject: urgent..creating loops in output xml based on input xml values..
From: ma he <mahendranvm@xxxxxxxxxxx>
Date: Mon, 12 Sep 2005 10:14:52 +0100 (BST)
xml.close
Hi all,
I am new to the whole xsl world and I have trouble
creating an xsl. This is urgent and I have less time
to do research. so plz help me with this asap.
This is my requirement,
 
the input xml will be in this format,
 
<root>
    <name>1</name>
    <name>2</name>
    <name>3</name>
    <name>1</name>
    <name>2</name>
    <name>1</name>
</root>
 
The possible values for name are only 1,2 and 3. I
should supply an xsl which will be used to transform
this xml into another xml in the following format,
 
<root>
  <Loop>
        <name>1</name>
        <Loop>
            <name>2</name>
            <Loop>
                <name>3</name>
            </Loop>
        </Loop>
    </Loop>
    <Loop>
        <name>1</name>
        <Loop>
            <name>2<name>
        </Loop>
    </Loop>
    <Loop>
        <name>1</name>
  </Loop>  
</root>
 
In the input xml, there will not be a 2 without 1
preceding it. similarly there wont be a 3 without a 2
preceding it. But there could be more than one 1 or 2
or 3, one after the other. Here's another example,
 
<root>
    <name>1</name>
    <name>2</name>
    <name>2</name>
</root>
 
Here the output will be
<root>
    <Loop>
        <name>1</name>
        <Loop>
            <name>2</name>
        </Loop>
        <Loop>
            <name>2</name>
        </Loop>
    </Loop>
</root>
 
I thought of using the following algorithm to
determine when to open a loop element and when to
close a loop,
 
declare variables L1 = no, L2 = no and L3 = no
For each <root> in output xml
{
    If (name = 1)
    {
        If (L3 = yes) then in output xml, close loop
"</Loop>
        If (L2 = yes) then in output xml, close loop
"</Loop>
        If (L1 = yes) then in output xml, close loop
"</Loop>
        Open Loop in output xml "<Loop>"
    }
    If (name = 2)
    {
        If (L3 = yes) then in output xml, close loop
"</Loop>
        If (L2 = yes) then in output xml, close loop
"</Loop>
        Open Loop in output xml "<Loop>"
    }
    If (name = 3)
    {
        If (L3 = yes) then in output xml, close loop
"</Loop>
        Open Loop in output xml "<Loop>"
    }
}
 
But here, since variable values once assigned cannot
be reassigned, I am not able to implement this algo.
in xsl. Help me with some other logic  that will be
able to achieve the same. (all I want here is to do
the following, there will be an input xml file where
all elements are in the same level. In the output
file, I want these elements nested one inside another,
based on their values.). Thanks in advance for ur
help.
-mahe


		
__________________________________________________________ 
Yahoo! India Matrimony: Find your partner now. Go to http://yahoo.shaadi.com

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.