Re: [xsl] Recursive selection, elegantly

Subject: Re: [xsl] Recursive selection, elegantly
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Sun, 06 Jun 2004 06:24:45 -0700
You could add an attribute like so:


<?xml version="1.0" encoding="UTF-8"?>
<root>
   <page about="/" onmenu="1">
     <name>Home</name>
   </page>
   <page about="/who_we_are" onmenu="1">
     <name>About us</name>
   </page>
   <page about="/contact_us" onmenu="1">
     <name>Contact us</name>
   </page>
   <page about="/disclaimer">
     <name>Disclaimer</name>
   </page>
   <category about="/mulberries" onmenu="1">
     <name>Top fruit</name>
   </category>
</root>


and then use Mukul's templates like:



The following XSL -


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="html" version="1.0"
encoding="UTF-8" indent="yes"/>

<xsl:template match="/root">
  <html>
    <head>
      <title/>
    </head>
    <body>
      <table>
	<tr>


<xsl:apply-templates select="*[boolean(@onmenu)]" mode="menu"/>


	</tr>
      </table>
    </body>
  </html>
</xsl:template>


<xsl:template match="*" mode="menu">


  <td>
    <a href="{@about}">
      <xsl:value-of select="name"/>
    </a>
  </td>
</xsl:template>

</xsl:stylesheet>

produces output -

<html>
<head>
  <title></title>
</head>
<body>
  <table>
    <tr>
      <td><a href="/">Home</a></td>
      <td><a href="/who_we_are">About us</a></td>
      <td><a href="/contact_us">Contact us</a></td>
      <td><a href="/disclaimer">Disclaimer</a></td>
    </tr>
  </table>
</body>
</html>

Regards,
Mukul


Current Thread