I have an xml with a list of persons, their database ids and a list of relations between them. It looks like this:
<root>
<person>
<id>1000</id>
<name>p1</name>
</person>
<person>
<id>1001</id>
<name>p2</name>
</person>
<rel>
<personid>1001</personid>
<personid>1000</personid>
</rel>
</root>
I’d like to generate using xslt 1.0 from java, the following:
person 2 relates to person 1.
The logic is to show the index of the person based on the order it appears in the xml.
My current ideas:
- preprocessing the xml in java and send a map as param to the xsl with [person_id, person_index] and then for each relation get the person_index from person_id
- making an xpath in xsl that finds the index of a person by a given id(although I don’t know to construct a xpath for that)
- preprocessing in java and construct the map, place it in a ThreadLocal variable and then from xsl calling another method that uses this ThreadLocal to get the person index from person id
Any other ideas, hopefully more simple are very appreciated.
Thanks!
No Java preprocessing or mapping is necessary.
This would generate one line of text for every
<rel>there is. It’s not a complete stylesheet, I’ll leave figuring out the rest to you.