Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7278503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:53:00+00:00 2026-05-28T22:53:00+00:00

I have an xml with a list of persons, their database ids and a

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:53:01+00:00Added an answer on May 28, 2026 at 10:53 pm

    No Java preprocessing or mapping is necessary.

    <xsl:key name="kPersonById" match="person" use="id" />
    
    <xsl:template match="rel">
      <xsl:text>Person </xsl:text>
      <xsl:value-of select="key('kPersonById', personid[1])/name" />
      <xsl:text> relates to </xsl:text>
      <xsl:value-of select="key('kPersonById', personid[2])/name" />
      <xsl:text>.&#10;</xsl:text>
    </xsl:template>
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have xml that looks like this: <todo-list> <id type=integer>#{id}</id> <name>#{name}</name> <description>#{description}</description> <project-id
Lets say you have an XML like like this: <data> <messages> <message name=Person id=P>
Hi I have the following XML structure: <Root> <Persons> <PersonList Category=Employee> <Person Name=John Id=5
I have the following XML file <?xml version=1.0 ?> <Persons> <Person> <Id>1</Id> <Name>temp</Name> <Qlid>1234</Qlid>
I have an XML file with this structure: <?xml version=1.0> <person> <element att1=value1 att2=value2>Anonymous</element>
I have a class PersonList [XmlRoot(Persons)] PersonList : List<Human> when I serialize this to
I have made a XML parser that list correctly in the UITableViewController. It passes
I have a list of xml elements that i need to search for specific
I'm trying to access list data using SSRS 2008. I have created an XML
I have a list of inactive_products in an XML file. I need to update

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.