How to iterate through nodes of xml through xslt

Hi, I have two xml files. *File1.xml* *<?xml version="1.0" encoding="UTF-8"?>* *<InfoTag>* *<Procedure attrProc="TestProcA" attrLevel="1">* * <downTime>* * <acceptableDownTime>* * <all/>* * </acceptableDownTime>* * <downTimePeriod time="600000000"/>* * </downTime>* * </Procedure>* * <Procedure attrProc="TestProcB" attrLevel="2">* * <downTime>* * <acceptableDownTime>* * <all/>* * </acceptableDownTime>* * <downTimePeriod time="600000000"/>* * </downTime>* * </Procedure>* *</InfoTag>* *File2.xml* *<?xml version="1.0" encoding="UTF-8"?>* *<InfoTag>* *<Procedure attrProc="TestProcC" attrLevel="3">* * <downTime>* * <acceptableDownTime>* * <all/>* * </acceptableDownTime>* * <downTimePeriod time="600000000"/>* * </downTime>* * </Procedure>* * <Procedure attrProc="TestProcD" attrLevel="4">* * <downTime>* * <acceptableDownTime>* * <all/>* * </acceptableDownTime>* * <downTimePeriod time="600000000"/>* * </downTime>* * </Procedure>* *</InfoTag>* I am trying to fetch an output file which looks like this: *Output.xml* *<InfoTag>* *<Procedure attrProc="1" attrLevel="### NOT UNIQUE ###">* * <downTime>* * <acceptableDownTime>* * <all/>* * </acceptableDownTime>* * <downTimePeriod time="600000000"/>* * </downTime>* * </Procedure>* * <Procedure attrProc="2" attrLevel="### NOT UNIQUE ###">* * <downTime>* * <acceptableDownTime>* * <all/>* * </acceptableDownTime>* * <downTimePeriod time="600000000"/>* * </downTime>* * </Procedure>* *<Procedure attrProc="3" attrLevel="### NOT UNIQUE ###">* * <downTime>* * <acceptableDownTime>* * <all/>* * </acceptableDownTime>* * <downTimePeriod time="600000000"/>* * </downTime>* * </Procedure>* * <Procedure attrProc="4" attrLevel="### NOT UNIQUE ###">* * <downTime>* * <acceptableDownTime>* * <all/>* * </acceptableDownTime>* * <downTimePeriod time="600000000"/>* * </downTime>* * </Procedure> * *</InfoTag>* The number of Procedure tag (<Procedure>) can be different every time. So I have to read this tag every time from each xml and then merge it sequentially. Can anyone tell me how to achieve this. How can I loop every Procedure tag and and append the attrProc attribute value in a sequential order? Thanks, BR, Varun

varun bhatnagar schrieb am 31.07.2014 um 09:32:
Could you describe in words how you get from the input to the output? Meaning, what are you trying to achieve? It's not clear to me from looking at the files. You seem to be concatenating the content of two files, but also change them somehow. Concatenation is easy, just extend the root element with the children of the other element ("r1.extend(r2)"). Do you need to sort them on the way? There's the sorted() function in Python. Or do they come in order already? Then you just need to merge them as in the mergesort algorithm. That's more efficient than sorting, but that may or may not make a visible difference here. Stefan

Hi Stefan, Thanks a ton for the reply! I have few xml files (depends on user how much he/she wants to pass). I have to take those files and merge them, so I have created a loop and in that I am passing these files one by one to lxml. For this I have written few rules to merge. But there is this <Procedure> tag where I am stuck. To merge this I need to parse each Procedure and have to modify its attributes (attrProc and attrLevel). I have to replace the attrProc attribute with a sequential value and for me this will set a unique "Level" for each Procedure tag and later I will process them based on their level. This is why I am looking for a loop where in based on the occurrences of Procedure tag I can set the level one by one sequentially. Thanks, BR, Varun On Fri, Aug 1, 2014 at 7:38 AM, Stefan Behnel <stefan_ml@behnel.de> wrote:

varun bhatnagar schrieb am 31.07.2014 um 09:32:
Could you describe in words how you get from the input to the output? Meaning, what are you trying to achieve? It's not clear to me from looking at the files. You seem to be concatenating the content of two files, but also change them somehow. Concatenation is easy, just extend the root element with the children of the other element ("r1.extend(r2)"). Do you need to sort them on the way? There's the sorted() function in Python. Or do they come in order already? Then you just need to merge them as in the mergesort algorithm. That's more efficient than sorting, but that may or may not make a visible difference here. Stefan

Hi Stefan, Thanks a ton for the reply! I have few xml files (depends on user how much he/she wants to pass). I have to take those files and merge them, so I have created a loop and in that I am passing these files one by one to lxml. For this I have written few rules to merge. But there is this <Procedure> tag where I am stuck. To merge this I need to parse each Procedure and have to modify its attributes (attrProc and attrLevel). I have to replace the attrProc attribute with a sequential value and for me this will set a unique "Level" for each Procedure tag and later I will process them based on their level. This is why I am looking for a loop where in based on the occurrences of Procedure tag I can set the level one by one sequentially. Thanks, BR, Varun On Fri, Aug 1, 2014 at 7:38 AM, Stefan Behnel <stefan_ml@behnel.de> wrote:
participants (2)
-
Stefan Behnel
-
varun bhatnagar