Re: Variable number of attributes

Subject: Re: Variable number of attributes
From: "John E. Simpson" <simpson@xxxxxxxxxxx>
Date: Sat, 30 Sep 2000 12:53:49 -0400
At 09:17 AM 09/30/2000 -0400, John E. Simpson wrote:
[Not 100% correct stylesheet]

Sorry - copy-and-paste error. The example previously posted does not output the table headers. It should have actually been:


<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   xmlns="http://www.w3.org/TR/REC-html40"; >

   <xsl:template match="/doc">
     <html>
       <head><title>Attributes to Elements</title></head>
       <body>
         <table>
           <tr>
             <xsl:for-each select="ele[1]/@*">
               <th><xsl:value-of select="name()"/></th>
             </xsl:for-each>
           </tr>
           <xsl:apply-templates />
         </table>
       </body>
     </html>
   </xsl:template>

   <xsl:template match="ele">
     <tr>
       <xsl:for-each select="@*">
         <td><xsl:value-of select="."/></td>
       </xsl:for-each>
     </tr>
   </xsl:template>

</xsl:stylesheet>

And the output from Saxon is:

<html xmlns="http://www.w3.org/TR/REC-html40";>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Attributes to Elements</title>
  </head>
  <body>
    <table>
      <tr>
        <th>name1</th>
        <th>name2</th>
        <th>name3</th>
      </tr>
      <tr>
        <td>A1</td>
        <td>A2</td>
        <td>A3</td>
      </tr>
      <tr>
        <td>B1</td>
        <td>B2</td>
        <td>B3</td>
      </tr>
    </table>
  </body>
</html>

Sorry for the wasted bandwidth!

==========================================================
John E. Simpson | "Curiosity killed the cat,
http://www.flixml.org | but for a while I was a
XML Q&A: http://www.xml.com | suspect." (Steven Wright)



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread