XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 28th, 2004, 08:31 PM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 6
1 XSL file, 2 XML docs?

This may seem silly, but I'd like to use one XSL stylesheet and reference 2 different XML documents. Is this possible? The output will be HTML, I have a table where 1 cell has data from one XML doc and the other cell has data from a different XML doc.
__________________
Hello, old friend...

Reply With Quote
  #2  
Old February 28th, 2004, 10:15 PM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 285 fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 3 h 6 m 53 sec
Reputation Power: 6
You can use the xsl:document() function to access nodes
in an external XML document.

Here is a working example:

-------- a.xml --------
<?xml version="1.0" encoding="iso-8859-1"?>
<root>
<entry>
<day>mon</day>
<amount>34</amount>
<amount>43</amount>
</entry>
</root>

-------- b.xml --------
<?xml version="1.0" encoding="iso-8859-1"?>
<root>
<entry>
<day>mon</day>
<amount>12</amount>
<amount>13</amount>
</entry>
</root>

-------- a.xsl ---------
<?xml version="1.0" encoding="ISO-8859-1" ?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" />

<xsl:variable name="a" select="/"/>

<xsl:template match="/">
<xsl:for-each select="document('./b.xml')//entry" >
<xsl:value-of select="day" />
<xsl:text>: </xsl:text>
<!-- note the context! Currently document b -->
<xsl:value-of select="sum(//amount)" />
<xsl:text>, </xsl:text>
<xsl:value-of select="sum($a//amount)" />
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Reply With Quote
  #3  
Old March 2nd, 2004, 09:48 AM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 6
Thanks! Quick question:

document('./b.xml')

That means that b.xml would be in the same folder as a.xml and the stylesheet, right?

Can I put an absolute path in there, like

C:/XML/blah/b.xml

?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > 1 XSL file, 2 XML docs?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT