Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to transform normalized XML

Status
Not open for further replies.

NotMyRealName221

Programmer
Oct 28, 2008
8
0
0
US
I'm consuming some XML from a sevice that I have no control over. The XML is comming back something like this:
Code:
<root>
  <projects>
    <project>
      <id>1</id>
      <name>Project 1</name>
    </project>
    <project>
      <id>2</id>
      <name>Project 2</name>
    </project>
  </projects>
  <tasks>
    <task>
      <projectId>1</projectId>
      <name>task 1</name>
      <notes>Finish this task quickly</notes>
    </task>
    <task>
      <projectId>1</projectId>
      <name>task 2</name>
      <notes>Finish this task more quickly</notes>
    </task>
    <task>
      <projectId>2</projectId>
      <name>task 3</name>
      <notes>Finish this task slowly</notes>
    </task>
    <task>
      <projectId>1</projectId>
      <name>task 4</name>
      <notes>Finish this task first</notes>
    </task>
  </tasks>
</root>
ok, that should be enough XML...
I need to be able to output the data like this:

Project 1
task 1 Finish this task quickly
task 2 Finish this task more quickly
task 4 Finish this task first
Project 2
task 3 Finish this task slowly

I'm not sure how to relate the id in the project node to the projectId in the task node.

Thanks for any help
 
>I'm not sure how to relate the id in the project node to the projectId in the task node.
In this template, it shows you how to relate the context node "project" to its related tasks.
[tt]
<xsl:template match="project">
<!-- other stuff -->
<xsl:for-each select="../following-sibling::tasks/task[projectId=current()/id]">
<!-- process with the task node -->
</xsl:for-each>
<!-- other stuff -->
</xsl:template>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top