|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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... |
|
#2
|
|||
|
|||
|
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> |
|
#3
|
||||
|
||||
|
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 ? |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > 1 XSL file, 2 XML docs? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|