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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking Data Together to Display Correctly

Status
Not open for further replies.

Ccssrs69

Programmer
Jan 7, 2008
2
I new to the XSL thing and I'm have issues linking data together. I have an XML file like below and need help with get it to output correctly.

<doc>
<new id="22234" name="Bob">
<more id="22234" address="somewhere">
<more id="22234" address="somewhere else">
<new id="22235" name="George">
<more id="22235" address="somewhere new">
<new id="22236" name="Mike">
<more id="22236" address="new place">
<doc>

My XSL code looks something like this, but I'm not sure this can even be done.

<xsl:for-each select="/doc/new">
<xsl:value-of select="/doc/new/@name"/>
<xsl:for-each select="doc/new/@id = doc/new/more/@id">
<xsl:value-of select="doc/new/more/@address"/>
</xsl:for-each>
</xsl:for-each>

I have tried everything that I can think of, and I probably over looking something stupid, but I could use the help. I need the data to display like this.

Bob
somewhere
somewhere else
George
somewhere new
Mike
new place

Any help would be greatly appreciated and thanks in advance.



 
Ow,
First recheck your XML: it is not valid.

if you meant something like
Code:
<doc>
 <new id="22234" name="Bob">
  <more id="22234" address="somewhere" />
  <more id="22234" address="somewhere else" />
 </new>
 <new id="22235" name="George">
  <more id="22235" address="somewhere new" />
 </new>
 <new id="22236" name="Mike">
  <more id="22236" address="new place"/>
 </new>
<doc>

you could do with something like:
Code:
<xsl:for-each select="/doc/new">
 <xsl:value-of select="@name"/>
 <!-- find child-nodes of current (//new) node -->
 <xsl:for-each select="more">
  <xsl:value-of select="@address"/>
 </xsl:for-each>
</xsl:for-each>

However, if your XML is meant to be:
Code:
<doc>
 <new id="22234" name="Bob"/>
 <more id="22234" address="somewhere"/>
 <more id="22234" address="somewhere else"/>
 <new id="22235" name="George"/>
 <more id="22235" address="somewhere new"/>
 <new id="22236" name="Mike"/>
 <more id="22236" address="new place"/>
</doc>
you'd need something like:
Code:
<xsl:for-each select="/doc/new">
 <xsl:value-of select="@name"/>
 <!-- find all siblings / children or whatever called 'more'  having same @id -->
 <xsl:for-each select="//more[@id=current()/@id]">
  <xsl:value-of select="@address"/>
 </xsl:for-each>
</xsl:for-each>
(sorry, no time to test and parse, but I guess you'll get the idea)
 
Thanks alot Jel

The second option worked great. Just what I was looking for, once again thanks a ton.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top