I have an xml in the following format:
<?xml version="1.0" encoding="UTF-8"?>
<response>
<cases>
<case>CASE-ONE</case>
<case>CASE-TWO</case>
</cases>
<results>
<Final-Results>
<issues>
<row>
<IKEY>2014-03-26-05.22.22.193840T01</IKEY>
<PRTY>999</PRTY>
</row>
</issues>
</Final-Results>
<Final-Results>
<issues>
<row>
<IKEY>2014-03-26-05.05.51.077840T01</IKEY>
<PRTY>999</PRTY>
</row>
<row>
<IKEY>2014-03-26-05.10.51.077840T01</IKEY>
<PRTY>999</PRTY>
</row>
</issues>
</Final-Results>
</results>
</response>
Now, I want to convert the above xml to the following format using XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<response>
<cases>
<case>
CASE-ONE
<issues>
<row>
<IKEY>2014-03-26-05.22.22.193840T01</IKEY>
<PRTY>999</PRTY>
</row>
</issues>
</case>
<case>
CASE-TWO
<issues>
<row>
<IKEY>2014-03-26-05.05.51.077840T01</IKEY>
<PRTY>999</PRTY>
</row>
<row>
<IKEY>2014-03-26-05.10.51.077840T01</IKEY>
<PRTY>999</PRTY>
</row>
</issues>
</case>
</cases>
</response>
The idea is to move the content between the first <issues> </issues>
tags to the first <case> </case>
tags and the second <issues> </issues>
tags to the second tags and so on. Here the number of <case>
tags and <issues>
tags are uncertain. So,I think I have to use for loop kind of thing here.Honestly, I am not expert in using XSLT. It would be great if you can provide a solution. Please feel free to add a comment if my question is not clear so that I can put it in better words.
Thanks in advance.
No need to use a for loop. Use the identity transform and
xsl:apply-templates
instead.XML Input
XSLT 1.0
XML Output
The following stylesheet produces the desired result:
I could think of this way: