PDA

View Full Version : XML/XSLT: Reading in xml files



munkyeetr
December 18th, 2008, 05:55 PM
I am new to using xml/xslt and this is my situation:

I have an xml file (index.xml) which is rendered using the stylesheet index.xsl. This works great.

Now, from index.xsl I want to read in my footer information which is stored in the file footer.xml.



<!-- This is footer.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<footer>
<line text="some footer text here"/>
<line text="some more footer text here"/>
</footer>


I have tried a bunch of different ways to do this, none successful. Here's the last way I tried; this code is in index.xsl:


<xsl:for-each select="document('footer.xml')/line">
<xsl:value-of select="@text" /><br />
</xsl:for-each>


and I get nothing. As I say, I've tried a bunch of stuff and nothing has worked so far. There has to be an easy way in XSLT to say:

1) Use this file (footer.xml)
2) Read this/these nodes

Any help, code snippet, or a push in the right direction is appreciated.

Sportingfan
February 26th, 2009, 11:11 AM
Are you referring to the xsl stylesheet in your footer.xml?
Read the tutorial on w3schools (http://www.w3schools.com/xsl).

hastur
February 26th, 2009, 03:23 PM
hi,

your XPath is wrong, I tried with :



document('footer.xml')/footer/line

and with


document('footer.xml')//line


and it works fine