Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with XSLT

 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an XML which is not properly structured , i have to parse and display it with XSLT.

<information>
<records>

<personname>
<name>aaaa</name>
</personname>
<postaladdress>
<address>xhfsdfhlsd</address>
</postaladdress>

<personname>
<name>bbbb</name>
</personname>
<postaladdress>
<address>sdueiour</address>
</postaladdress>

<personname>
<name>cccc</name>
</personname>
<postaladdress>
<address>heorurot</address>
</postaladdress>

</records>
</information>

That personname and postaladdress tag will repreat different number of times in different xmls

Now I am not understanding how to pull those in that order , because i can not use a for-each there,as it will dispay one after another.

Anybody has any idea?
Thanks in advance
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Archana Annamaneni:

Now I am not understanding how to pull those in that order , because i can not use a for-each there,as it will dispay one after another.

IMHO, i dont understand why cant you use xsl:for-each, can you explain again.
 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes because if i use

<information>
<records>
<xsl:for-each select="/information/records/personname>
..........
</xsl:for-each>
<xsl:for-each select="/information/records/postaladdress>
.........
</xsl:for-each>
</information>
</records>

If i do like this it will display all the personname first and then all the postaladdress.

If i use loop inside loop postaladdress will come 4 times
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No that will not happen.
You are mixing xml and xslt and xpath.
I would suggest you to read the beginners tutorial on xsl and xpath from w3schools site which i pointed out in your other post.
 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks , I been reading the w3schools.

I don't know whether you observed or not if in my xml
Personame and postaladdress had a parent tag combining those two , the problem wont be there,as you said with for-each it will disply.

But here the personname and postaladdress tags are repeating inside records , I still don't understand how it is going to work?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you want to change your badly designed XML document into something more useful, such as this:

I don't think there is a way of using XSLT to do this - since you have no data in your personname element which links it to a specific postaladdress record. You can't rely on the positioning of one element next to another in XML, only an element's position in the docuement hierarchy and any attributes/value it might have. So basically, its not going to work. And thats a deliberate limitation of XML/XSLT.
 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks I found the solution ,I think xpath has solution
 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought I found the solution , but it seems i don't.

whatever i do it is returning only the first records.

Balaji do you think there is a solution for this , if you do please let me know
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Archana Annamaneni:
Balaji do you think there is a solution for this , if you do please let me know

Can you the post the input XML and the expected output.
 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure Here is the input xml


And here is the output code



Just added a parent tag combing two tags in the output.Let me know if you have any more questions
 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved the problem through JAVA using DOM
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic