Click to See Complete Forum and Search --> : 2 XML Docs > 1 XSLT Stylesheet


kwilliams
09-09-2005, 10:28 AM
I've posted this question before with no response, so I decided to simplify my explanation in hopes of making it easier to understand what I'm asking about:

I have 2 XML docs:
1) xmldoc1.xml - This file contains a central list of external links for our entire website. This is how it's set up:
<xmldoc1>
<site id="site1">
<url>http://www.site1.com/</url>
</site>
<site id="site2">
<url>http://www.site2.com/</url>
</site>
</xmldoc1>

2) xmldoc2.xml - This file contains a node named "link" that matches one of the "id" attributes from xmldoc1.xml. This is how it's set up:
<xmldoc2>
<item>
<title>SITE 1</title>
<address>123 4th St.</address>
<phone>(123) 456-7890</phone>
<link>site1</link>
</item>
<item>
<title>SITE 2</title>
<address>987 6th St.</address>
<phone>(987) 654-3210</phone>
<link>site2</link>
</item>
</xmldoc2>

And this is what I'd like the output to look like:

SITE 1
Address: 123 4th St.
Phone: (123) 456-7890
Website: http://www.site1.com/

SITE 2
Address: 987 6th St.
Phone: (987) 654-3210
Website: http://www.site2.com/

I know that I need an XSLT stylesheet that ties the 2 source XML docs together using the "id" attribute from xmldoc1.xml, and the "link" node from xmldoc2.xml, but I'm not sure how to accomplish this. I've been beating my head against a wall concerning what I thought would be a simple task, so I'm now hoping that some knowledgable folks can show me the light so-to-speak.

So if anyone can give me some insight in how to accomplish this task, it would be greatly appreciated!!! Thanks so much for your time.

theuedimaster
09-09-2005, 04:49 PM
I don't understand why you're making two xml pages, you should combine them into one. It would be more efficient.

kwilliams
09-09-2005, 05:23 PM
I don't understand why you're making two xml pages, you should combine them into one. It would be more efficient.
The first document contains every external link that's referenced throughout the site, and the second document refrences that central document as many other pages do. I personally don't believe that it would be more efficient to have 100+ more nodesets on each page than it would be to have one central document that's referenced by several others using the document() function.

Another forum provided me with a great working answer, and it can be seen at http://p2p.wrox.com/topic.asp?TOPIC_ID=34629. Thanks.

sheila
09-15-2005, 04:41 PM
I understand why, I do the same thing myself all the time.

Try:

<item>
<title>SITE 2</title>
<address>987 6th St.</address>
<phone>(987) 654-3210</phone>
<link ref="site2" />
</item>

And then use the value of @ref to lookup the site in your links db.