Subject: [xsl] 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) |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Re: 3 elements on the same li, bharathi kongara | Thread | RE: [xsl] urgent..creating loops in, Michael Kay |
RE: [xsl] Dynamic path in xsl:impor, Michael Kay | Date | Re: [xsl] Can I use <xsl:key>, Ragulf Pickaxe |
Month |