[XML-SIG] Merry Xmas Courtesy 4XSLT

uche.ogbuji@fourthought.com uche.ogbuji@fourthought.com
Mon, 20 Dec 1999 01:58:28 -0700


This is a multipart MIME message.

--==_Exmh_11745643960
Content-Type: text/plain; charset=us-ascii

OK, it's somewhat silly, but I can't resist.  Who says XSLT is only for 
juggling XML?

The attachment works with 4XSLT 0.9.0

Gaudete!


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


--==_Exmh_11745643960
Content-Type: text/plain; name="xslt-xmas.py"; charset=us-ascii
Content-Description: xslt-xmas.py
Content-Disposition: attachment; filename="xslt-xmas.py"

#Demonstrates some basic programming

from Ft.Xslt.Processor import Processor
import Ft.Dom.Ext
from Ft.Dom.Ext.Reader import Sax2

sheet_str_2 = """<?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>"""

def test():
    processor = Processor()
    sheet = Sax2.FromXml(sheet_str_2)
    xml_dom = Sax2.FromXml(xml_source)
    processor.appendStylesheetNode(sheet)
    result = processor.run(xml_dom, ignorePis=1)
    print 
    print result


if __name__ == '__main__':
    test()

--==_Exmh_11745643960--