Xmas Tree

Subject: Xmas Tree
From: uche.ogbuji@xxxxxxxxxxxxxxx
Date: Mon, 20 Dec 1999 02:02:15 -0700
Michael Kay's sheet was a neat trick, but I couldn't find a Christmas Cracker 
in it.  Here's a more straightforward offering.  Merry Christmas.

===========Stylesheet==============
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output method="text"/>

<xsl:template match="/">
  <xsl:variable name='width' select='number(*)'/>
  <xsl:text>'****Merry Xmas!****'&#10;&#10;</xsl:text>
  <xsl:call-template name='print_row'>
    <xsl:with-param name="curr_width" select="$width"/>
    <xsl:with-param name="total_width" select="$width"/>
  </xsl:call-template>
</xsl:template>

<xsl:template name="print_row">
  <xsl:param name="curr_width"/>
  <xsl:call-template name='spacer'>
    <xsl:with-param name="counter" select="$curr_width div 2"/>
  </xsl:call-template>
  <xsl:call-template name='next_in_row'>
    <xsl:with-param name="counter" select="$total_width - $curr_width"/>
  </xsl:call-template>
  <xsl:if test='$curr_width != 1'>
  <xsl:call-template name='print_row'>
    <xsl:with-param name="curr_width" select="$curr_width - 2"/>
    <xsl:with-param name="total_width" select="$total_width"/>
  </xsl:call-template>
  </xsl:if>
</xsl:template>

<xsl:template name="next_in_row">
  <xsl:param name="counter"/>
  <xsl:text>*</xsl:text>
  <xsl:choose>
    <xsl:when test='$counter != 0'>
      <xsl:call-template name='next_in_row'>
        <xsl:with-param name="counter" select="$counter - 1"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>&#10;</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="spacer">
  <xsl:param name="counter"/>
  <xsl:text> </xsl:text>
    <xsl:if test='floor($counter) != 0'>
      <xsl:call-template name='spacer'>
        <xsl:with-param name="counter" select="$counter - 1"/>
      </xsl:call-template>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>


===========XML Source==============
<tree-width>15</tree-width>


-- 
Uche Ogbuji
FourThought LLC, IT Consultants
uche.ogbuji@xxxxxxxxxxxxxxx	(970)481-0805
Software engineering, project management, Intranets and Extranets
http://FourThought.com		http://OpenTechnology.org



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


Current Thread
  • Xmas Tree
    • uche . ogbuji - Mon, 20 Dec 1999 02:02:15 -0700 <=