xsl-list
[Top] [All Lists]

Re: MSXML 4 - RowSetSchema XML

2004-02-17 02:24:49
This is a transform I use for showing information. It's designed to produce an html table from an MS ado row set saved as xml. It's not very sophisticated but you can probably improve it:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'
exclude-result-prefixes="s dt rs z">

 <xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes"/>
 <xsl:template match="/">
<xsl:variable name="fieldData" select="xml/s:Schema/s:ElementType/s:AttributeType[not(@rs:hidden)]"/>
   <xsl:variable name="columnCount" select="count($fieldData)"/>
   <xsl:variable name="columnWidth" select="floor(100 div $columnCount)"/>
   <div id="divMain" style="margin:0px">
     <table border="1" width="100%" cols="{$columnCount}">
       <thead>
         <tr style="font-size:9pt;background-color:#0000cc;color:#ffffff">
           <xsl:apply-templates select="$fieldData">
             <xsl:with-param name="columnWidth" select="$columnWidth"/>
           </xsl:apply-templates>
         </tr>
       </thead>
       <xsl:apply-templates select="xml/rs:data">
         <xsl:with-param name="fieldData" select="$fieldData"/>
         <xsl:with-param name="columnCount" select="$columnCount"/>
         <xsl:with-param name="columnWidth" select="$columnWidth"/>
       </xsl:apply-templates>
     </table>
     <br/>
   </div>
 </xsl:template>
 <xsl:template match="s:AttributeType">
   <xsl:param name="columnWidth"/>
   <th width="{$columnWidth}%">
     <xsl:choose>
       <xsl:when test="@rs:name">
         <xsl:value-of select="@rs:name"/>
       </xsl:when>
       <xsl:otherwise>
         <xsl:value-of select="@name"/>
       </xsl:otherwise>
     </xsl:choose>
   </th>
 </xsl:template>
 <xsl:template match="rs:data">
   <xsl:param name="fieldData"/>
   <xsl:param name="columnCount"/>
   <xsl:param name="columnWidth"/>
   <tbody style="color:#0000cc;font-size:9pt;">
     <xsl:apply-templates>
       <xsl:with-param name="fieldData" select="$fieldData"/>
       <xsl:with-param name="columnWidth" select="$columnWidth"/>
     </xsl:apply-templates>
   </tbody>
 </xsl:template>
 <xsl:template match="z:row">
   <xsl:param name="fieldData"/>
   <xsl:param name="columnWidth"/>
   <xsl:variable name="currentRow" select="."/>
   <tr style="font-size:9pt;">
     <xsl:for-each select="$fieldData">
       <td width="{$columnWidth}%">
         <xsl:attribute name="align">
           <xsl:choose>
             <xsl:when test="s:datatype/@dt:type = 'string'">
               <xsl:value-of select="'left'"/>
             </xsl:when>
             <xsl:otherwise>
               <xsl:value-of select="'right'"/>
             </xsl:otherwise>
           </xsl:choose>
         </xsl:attribute>
<xsl:variable name="currentData" select="$currentRow/@*[name() = current()/@name]"/>
         <xsl:choose>
           <xsl:when test="$currentData != ''">
             <xsl:choose>
               <xsl:when test="s:datatype/@rs:dbtype = 'currency'">
<xsl:value-of select="format-number($currentData, '#,##0')"/>
               </xsl:when>
               <xsl:when test="s:datatype/@rs:dbtype = 'timestamp'">
<xsl:value-of select="concat(substring($currentData, 9, 2), '/', substring($currentData, 6, 2), '/', substring($currentData, 1, 4))"/>
               </xsl:when>
             </xsl:choose>
           </xsl:when>
           <xsl:otherwise>
             <xsl:value-of select="'&#xa0;'"/>
           </xsl:otherwise>
         </xsl:choose>
       </td>
     </xsl:for-each>
   </tr>
 </xsl:template>
</xsl:stylesheet>



Joe

_________________________________________________________________
Sign-up for a FREE BT Broadband connection today! http://www.msn.co.uk/specials/btbroadband


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



<Prev in Thread] Current Thread [Next in Thread>