Reading and processing multiple xml documents
Hey,
I have a personal project that i though i would tackle with XSLT and XML as i have not used them before and thought it would be a good tool to have under my belt for the future.
Basically, i have two xml files:
structure.xml - used to store details about the site structure
products.xml - used to store product details
I want to create multiple web pages from a single stylesheet, so far i have the following:
structure.xml:
<departments>
<department continent="Europe" img="europe.jpg">
<sub-department country="United Kingdom" img="uk.jpg"/>
<sub-department country="Germany" img="germany.jpg"/>
<sub-department country="France" img="france.jpg"/>
<sub-department country="Netherlands" img="netherlands.jpg"/>
</department>
</departments>
products.xml:
<destinations>
<destination continent="Europe" country="United Kingdom" city="London">
<images img="london_main.jpg"/>
<description>Information about london</description>
<hotels>
<hotel name="London Hilton" rating="5">
<images img1="lh_main.jpg" img2="lh_lobby.jpg"/>
<description>Info about london hilton hotel</description>
<prices single="£30.00" double="£50.00" suite="£130.00"/>
</hotel>
</hotels>
</destination>
<destination continent="Europe" country="United Kingdom" city="Cardiff">
<images img="cardiff_main.jpg"/>
<description>Information about cardiff</description>
<hotels>
<hotel name="Cardiff Sleeperz" rating="3">
<images img1="cs_main.jpg" img2="cs_lobby.jpg"/>
<description>Info about cardiff sleepers hotel</description>
<prices single="£20.00" double="£40.00" suite="£100.00"/>
</hotel>
</hotels>
</destination>
<destination continent="Europe" country="United Kingdom" city="Belfast">
<images img="belfast_main.jpg"/>
<description>Information about belfast</description>
<hotels>
<hotel name="Belfast Hilton" rating="5">
<images img1="bh_main.jpg" img2="bh_lobby.jpg"/>
<description>Info about Belfast hilton hotel</description>
<prices single="£30.00" double="£50.00" suite="£130.00"/>
</hotel>
</hotels>
</destination>
<destination continent="Europe" country="United Kingdom" city="Glasgow">
<images img="glasgow_main.jpg"/>
<description>Information about glasgow</description>
<hotels>
<hotel name="Glasgow Grand" rating="5">
<images img1="gg_main.jpg" img2="gg_lobby.jpg"/>
<description>Info about glasgow hotel</description>
<prices single="£40.00" double="£70.00" suite="£150.00"/>
</hotel>
</hotels>
</destination>
</destinations>
structure.xsl (so far):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="html" indent="yes" name="html"/>
<xsl:variable name="departments" select="document(structure.xml)"/>
<xsl:variable name="destinations" select="document(products.xml)"/>
<xsl:template match="/">
<xsl:result-document href="index.html" format="html" indent="yes">
<html>
<body>
<table>
<tr>
<xsl:for-each select="//department">
<xsl:variable name="department" select="@continent" />
<xsl:variable name="image" select="concat('Images/',$department,'/',$department,'_main.jpg')"/>
<td>
<a href="{$department}.html"><img alt="{$department}" src="{$image}"/></a>
<br />
<p><xsl:value-of select="$department"/></p>
</td>
<xsl:result-document href="{$department}.html">
<html>
<head>
<title></title>
</head>
<body>
<table>
<tr>
<xsl:for-each select="sub-department">
<td>
<xsl:variable name="sub-department" select="@country" />
<xsl:variable name="image" select="concat('Images/',$department,'/',$sub-department,'/',$sub-department,'_main.jpg')"/>
<xsl:result-document href="{$department}/{$sub-department}.html">
<html>
<head>
<title></title>
</head>
<body>
<table>
<tr>
<xsl:variable name="test" select="document('destinations.xml')"/>
<xsl:for-each select="test/destination">
<td>
<p><xsl:value-of select="@city"/></p>
</td>
</xsl:for-each>
</tr>
</table>
</body>
</html>
</xsl:result-document>
<a href="{$department}/{$sub-department}.html"><img alt="{$sub-department}" src="{$image}"/></a>
<br />
<p><xsl:value-of select="$sub-department"/></p>
</td>
</xsl:for-each>
</tr>
</table>
</body>
</html>
</xsl:result-document>
</xsl:for-each>
</tr>
</table>
</body>
</html>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
what im stuck on atm is opening/accessing the products.xml, and being able to populate pages with products.
any help would be amazing as this has been bugging me for weeks, and i cant seem to get my head around it!
cheers
|