Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 11th, 2011, 12:08 PM
Registered User
 
Join Date: Mar 2011
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Biztalk Multiple File processing Kswetha Biztalk 0 January 13th, 2009 07:30 AM
multiple input documents pcase XSLT 2 January 8th, 2008 07:51 PM
outputting to multiple documents? wilgartw XSLT 3 November 7th, 2007 07:52 PM
Processing a list of word documents from VB rohan101 Pro VB 6 2 February 16th, 2004 09:24 AM
Referencing multiple XML documents... qornboy XML 3 October 9th, 2003 09:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.