[xsl] Using values from one node tree to iterate/recurse over another set of nodes. (Newbie Question)

Subject: [xsl] Using values from one node tree to iterate/recurse over another set of nodes. (Newbie Question)
From: Richard Dyce <subscriptions@xxxxxxxx>
Date: Wed, 27 Feb 2008 15:01:21 +0000
Hi,

I'm just hoping for someone to give me a nudge in the right direction (given that I'm so far out of my depth, that a snorkel isn't going to help...)

I have a simple XML fragment:

<?xml version="1.0"?>
<view action="list" controller="story" display="list">
<record_list begin_record="1" end_record="2" last_page="1" page_number="1" page_size="10" total_found="2" type="story">
<structure>
<field label="ID" name="id" type="id">id</field>
<field label="Headline" name="headline" type="name">headline</ field>
<field label="Bodycopy" name="bodycopy" type="textarea">bodycopy</field>
<field label="Picture" name="picture" type="image">picture</field>
</structure>
<record sig="47c44488b7a614.15734104" type="story">
<id>2</id>
<headline>Fog in Channel, Europe Cut Off</headline>
<bodycopy>There was fog in the channel. No French cheese for us.</bodycopy>
<picture>cheese.png</picture>
</record>
<record sig="47c44488bb80e5.13211401" type="story">
<id>1</id>
<headline>Man Bites Dog</headline>
<bodycopy>Today a man bit a dog</bodycopy>
<picture>dog.png</picture>
</record>
</record_list>
</view>


and I want to use the <structure> element as field definitions to format the <record> elements as rows in an HTML table.

What I have so far is:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output method="html"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />


<xsl:template match="/">
 <xsl:call-template name="head" />
 <body>
   <xsl:apply-templates select="//view" />
 </body>
</xsl:template>

<xsl:template match="view[@display='list']">
 <xsl:variable name="rec_type" select="record_list/@type"/>
 <xsl:variable name="total_found" select="record_list/@total_found"/>
 <xsl:variable name="page_size" select="record_list/@page_size"/>
 <xsl:variable name="page_number" select="record_list/@page_number"/>
 <xsl:variable name="last_page" select="record_list/@last_page"/>
 <xsl:variable name="structure" select="record_list/structure"/>

<h2><xsl:value-of select="$rec_type"/> Listing</h2>
<p>Showing <xsl:value-of select="record_list/@begin_record"/> to <xsl:value-of select="record_list/@end_record" /> of <xsl:value-of select="$total_found" /> records</p>
<xsl:apply-templates select="record_list/record">
<xsl:with-param name="structure" select="$structure" />
</xsl:apply-templates>
</xsl:template>


<xsl:template match="record">
 <xsl:param name="structure"/>

 <!-- newbie problem !!!! -->
 <xsl:value-of select="$structure" />
 <xsl:value-of select="." />

</xsl:template>

</xsl:stylesheet>


What I want to be able to do is recurse through the structure, pulling the definitions from the attributes, and the values from each record.


At least, that's what I *think* I want to do, but I'm at the very bottom of the steep learning curve, and, well, any general pointers would be greatly appreciated.

(I'm using XSLT 1.0 I'm afraid)

--
Richard Dyce MA (Cantab.) MBCS MIET

Current Thread