Welcome Guest, you are in: Login

Daisley-Harrison Software

RSS RSS

Navigation




Search the wiki
»
The examples helper xslt file (ExamplesHelper.xslt) is include in a number of the example xslt markup processors.


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output method="html" indent="yes"/>
  <!-- The show-node-as-table template creates a table out of the attributes and children of a node -->

  <xsl:template name="show-node-as-table">
    <xsl:param name="title"/>
    <xsl:param name="node"/>

    <xsl:variable name="columns">
      <xsl:choose>
        <xsl:when test="count($node/@*) &lt;= 0">
          <xsl:value-of select="1"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="count($node/@*)"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <table cellpadding="0" cellspacing="0" class="generic">
      <thead>
      <tr  class="tableheader">
        <th colspan="{$columns}">
          <xsl:value-of select="$title"/>
        </th>
      </tr>
      <tr>
        <th colspan="{$columns}">
          <xsl:value-of select="name($node)"/>
        </th>
      </tr>
      <xsl:if test="text()">
        <tr>
          <td colspan="{$columns}">
            <xsl:value-of select="."/>
          </td>
        </tr>
      </xsl:if>
      <tr>
        <xsl:for-each  select="$node/@*">
          <th>
            <xsl:value-of select="name()"/>
          </th>
        </xsl:for-each>
      </tr>
      <tr>
        <xsl:for-each  select="$node/@*">
          <td>
            <xsl:value-of select="."/>
          </td>
        </xsl:for-each>
      </tr>
      </thead>
      <tbody>
        <xsl:for-each select="$node/node()">
          <xsl:variable name="row-class">
            <xsl:choose>
              <xsl:when test="position() mod 2 = 0">
                <xsl:text>tablerowalternate</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text>tablerow</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:variable>
          <tr class="{$row-class}">
            <th>
              <xsl:value-of select="name()"/>
            </th>
            <td>
              <xsl:call-template name="show-node-as-table">
                <xsl:with-param name="title"/>
                <xsl:with-param name="node" select="."/>
              </xsl:call-template>
            </td>
          </tr>
        </xsl:for-each>
      </tbody>
    </table>
  </xsl:template>

  <!-- The show-result-set-as-table template creates a table out of a result-set -->

  <xsl:template name="show-result-sets-as-tables">
    <xsl:param name="title"/>
    <xsl:param name="result-sets"/>
   <xsl:for-each select="$result-sets/result-set">
      <xsl:variable name="columns" select="count(schema/node())"/>
      <xsl:variable name="colspan">
        <xsl:choose>
          <xsl:when test="$columns &lt;= 0">
            <xsl:value-of select="1"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$columns"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
     <table  cellpadding="0" cellspacing="0" class="generic">
       <thead>
         <xsl:if test="$title">
           <tr>
             <th colspan="{$colspan}">
               <xsl:value-of select="$title"/>
             </th>
           </tr>
         </xsl:if>
         <tr>
           <xsl:for-each select="schema/column-definition">
             <th>
               <xsl:value-of select="@ColumnName"/>
             </th>
           </xsl:for-each>
         </tr>
       </thead>
       <tbody>
         <xsl:for-each  select="rows/row">
           <xsl:variable name="row-class">
             <xsl:choose>
               <xsl:when test="position() mod 2 = 0">
                 <xsl:text>tablerowalternate</xsl:text>
               </xsl:when>
               <xsl:otherwise>
                 <xsl:text>tablerow</xsl:text>
               </xsl:otherwise>
             </xsl:choose>
           </xsl:variable>
           <tr class="{$row-class}">
             <xsl:for-each  select="column">
               <td>
                 <xsl:value-of select="."/>
               </td>
             </xsl:for-each>
           </tr>
         </xsl:for-each>
       </tbody>
     </table>
      </xsl:for-each>
  </xsl:template>

  <!-- The show-node-as-xml template creates a html encoded xml out of the attributes and children of a node -->

  <xsl:template name="show-node-as-xml">
    <xsl:param name="node"/>
    <xsl:param name="indent"/>
    <xsl:value-of disable-output-escaping="yes" select="$indent"/>
    <xsl:text>&lt;</xsl:text>
    <xsl:value-of select="name($node)"/>
    <xsl:for-each  select="$node/@*">
      <xsl:text> </xsl:text>
      <xsl:value-of select="name()"/>
      <xsl:text>="</xsl:text>
      <xsl:value-of select="."/>
      <xsl:text>"</xsl:text>
    </xsl:for-each>
    <xsl:text>&gt;</xsl:text>
    <br/>
    <xsl:text>
</xsl:text>
    <xsl:if test="text()">
      <xsl:value-of disable-output-escaping="yes" select="$indent"/>
      <xsl:value-of select="."/>
      <br/>
      <xsl:text>
</xsl:text>
    </xsl:if>
    <xsl:for-each select="$node/node()">
      <xsl:if test="name()!=''">
        <xsl:call-template name="show-node-as-xml">
          <xsl:with-param name="indent" select="concat($indent,'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;')"/>
          <xsl:with-param name="node" select="."/>
        </xsl:call-template>
      </xsl:if>
    </xsl:for-each>
    <xsl:value-of disable-output-escaping="yes" select="$indent"/>
    <xsl:text>&lt;/</xsl:text>
    <xsl:value-of select="name($node)"/>
    <xsl:text>&gt;</xsl:text>
    <br/>
    <xsl:text>
</xsl:text>
  </xsl:template>

</xsl:stylesheet>







Please visit our blog at http://blog.daisley-harrison.com

- All Content © Copyright 2010 Daisley-Harrison Software - All Rights Reserved. - ScrewTurn Wiki version 3.0.1.400.