[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Using values from one node tree to iterate/recurse

Subject: Re: Using values from one node tree to iterate/recurse over another set of nodes. (Newbie Question)
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Wed, 27 Feb 2008 17:35:34 +0100
Re:  Using values from one node tree to iterate/recurse
Richard Dyce wrote:

Nothing too dramatic really -

<table>
  <tr>
    <th>ID</th>
    <th>Headline</th>
    <th>Bodycopy</th>
    <th>Picture</th>
  </tr>
  <tr>
    <td>2</th>
    <td>Fog in Channel, Europe Cut Off</td>
    <td>There was fog in the channel. No French cheese for us.</td>
    <td>cheese.png</td>
  </tr>
  <tr>
    <th>1</th>
    <td>Man Bite Dogs</td>
    <td>Today a man bit a dog</td>
    <td>dog.png</td>
  </tr>
</table>

But the point is that the structure needs to be dynamic...

This stylesheet achieves the described result, additionally adding thead and tbody:


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

<xsl:output method="html" indent="yes"/>

  <xsl:template match="/">
    <html lang="en">
      <head>
        <title>Example</title>
      </head>
      <body>
        <xsl:apply-templates select="view"/>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="view">
    <xsl:apply-templates select="record_list"/>
  </xsl:template>

<xsl:template match="record_list">
<h2><xsl:value-of select="@type"/> Listing</h2>
<p>Showing <xsl:value-of select="@begin_record"/> to <xsl:value-of select="@end_record" /> of <xsl:value-of select="@total_found" /> records</p>
<table>
<thead>
<xsl:apply-templates select="structure"/>
</thead>
<tbody>
<xsl:apply-templates select="record"/>
</tbody>
</table>
</xsl:template>


  <xsl:template match="structure">
    <tr>
      <xsl:apply-templates select="field"/>
    </tr>
  </xsl:template>

  <xsl:template match="field">
    <th>
      <xsl:value-of select="@label"/>
    </th>
  </xsl:template>

  <xsl:template match="record">
    <tr>
      <xsl:apply-templates select="*"/>
    </tr>
  </xsl:template>

  <xsl:template match="record/*">
    <td>
      <xsl:value-of select="."/>
    </td>
  </xsl:template>

</xsl:stylesheet>

It processes all child elements of record elements (match="record/*") so in that regard it is dynamic, it does however simply process those elements in the order they appear and does not look at the field elements, those are just used to create the thead.

As at least in your sample the field and record/* elements are in the same order the above might suffice. If not then post back.


--


	Martin Honnen
	http://JavaScript.FAQTs.com/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.