xsl-list
[Top] [All Lists]

Re: [xsl] OOXML

2008-06-28 07:50:18
But it set me thinking for real. If Dimitre can have FXSL, why can't I
have OOXSL (Dimitre, are you going to expel me now?)?



Colin,

I have done similar tings 6 years ago. For XSLT code that
*dynamically* creates the analog of classes with virtual functions
look here:

http://fxsl.sourceforge.net/articles/PartialApps/Partial%20Applications.html#5._Creating_a_new_function_dynamically_-_the_calculator_store_problem.

Approximately at that time I had implemented the XSLT 1.0 analog of a
Monad class and played with it a little. This allows to have
computations evaluated in a strict order. A much simpler demo how to
do perform actions in order is given by the XSLT Calculator:

   
http://fxsl.sourceforge.net/articles/xslCalculator/The%20FXSL%20Calculator.html

There is no problem implementing such concepts. However, it is simply
boring to follow the OO principles in a functional environment.


--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play





On Fri, Jun 27, 2008 at 11:13 PM, Colin Paul Adams
<colin(_at_)colina(_dot_)demon(_dot_)co(_dot_)uk> wrote:

"Colin" == Colin Paul Adams 
<colin(_at_)colina(_dot_)demon(_dot_)co(_dot_)uk> writes:

"Alexander" == Alexander Johannesen 
<alexander(_dot_)johannesen(_at_)gmail(_dot_)com> writes:
   Alexander> On Fri, Jun 27, 2008 at 21:58, John Snelson 
<john(_dot_)snelson(_at_)oracle(_dot_)com> wrote:
   >>> Maybe you've heard of a language called XSLT? Or XQuery? :-)

   Alexander> Cheap shot. :) Besides, I meant real programming
   Alexander> languages, not a faux functional LISP wannabe in XML
   Alexander> guise, with no OO, so there!

   Colin> :-)

   Colin> So use Eiffel! (with XSLT callouts when desired).

That was all very amusing (or not, according to your tastes).

But it set me thinking for real. If Dimitre can have FXSL, why can't I
have OOXSL (Dimitre, are you going to expel me now?)?

Given the following file oo_demo.xsl:

<?xml version="1.0" encoding="utf-8"?>
<!-- Demonstration of Object-Oriented programming in XSLT -->

<!--

This demonstrates an OO class named ACCOUNT, which represents a
 bank account equivalent to the following Eiffel class:

class ACCOUNT

feature - - Access

  balance: DOUBLE
       - - Balance of account in GBP

feature - - Basic operations

  deposit (a_value: DOUBLE) is
       - - Add `a_value' to `Current'.
     require
        a_value_strictly_positive: a_value > 0.0
     do
       balance := balance + a_value
     ensure
       deposited: balance = old balance + a_value
     end

   withdraw (a_value: DOUBLE) is
       - - Withdraw `a_value' from `Current'.
     require
        a_value_strictly_positive: a_value > 0.0
        no_overdrafts: a_value <- balance
     do
       balance := balance - a_value
     ensure
       deposited: balance = old balance - a_value
     end

invariant

  no_overdraft: balance >= 0.0

end

All operations are encoded in XML requests of the following forms:

<balance-enquiry/>

<deposit>a_positive_number</deposit>

<withdraw>a_positive_number</withdraw>

The document element is named requests. requests may take any number
 of balance-enquiry, deposit and withdraw children.

Contract-violation/error-checking code omitted for now.

-->


<xsl:transform
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:gexslt="http://www.gobosoft.com/eiffel/gobo/gexslt/extension";
  xmlns:exslt="http://exslt.org/system/environment";
  xmlns:account="http://colina.demon.co.uk/ooxsl/demo/account";
  extension-element-prefixes="gexslt"
  version="2.0">

 <xsl:output method="text"/>

 <xsl:template match="/requests">
   <xsl:apply-templates />
 </xsl:template>

 <xsl:template match="balance-enquiry">
   Balance is : <xsl:value-of select="account:balance()" />
 </xsl:template>

 <xsl:template match="deposit">
   <xsl:variable name="amount" select="text()" />
   <xsl:variable name="balance" select="account:balance()" />

   <gexslt:set-environment-variable name="ACCOUNT_BALANCE"
                                    value="$amount + $balance"/>
 </xsl:template>

 <xsl:template match="withdraw">
   <xsl:variable name="amount" select="text()" />
   <xsl:variable name="balance" select="account:balance()" />

   <gexslt:set-environment-variable name="ACCOUNT_BALANCE"
                                    value="$amount + $balance"/>
 </xsl:template>

 <xsl:function name="account:balance">
   <!-- Logic omitted for treating empty string as zero -->
   <xsl:value-of select="system-property('exslt:ACCOUNT_BALANCE')" />
 </xsl:function>

</xsl:transform>

and oo_demo.xml:

<requests>
 <balance-enquiry/>
 <deposit>3.45</deposit>
 <balance-enquiry/>
 <withdraw>1.45</withdraw>
 <balance-enquiry/>
</requests>


Then the command:

gestalt oo_demo.xsl oo_demo.xml

yields:


   Balance is :
 At line 84 in file:///home/colin/gestalt/oo_demo.xsl:
Fatal error: http://www.w3.org/2005/xqt-errors#XTDE1450: Unknown extension 
element: gexslt:set-environment-variable

But that's not too difficult to remedy.

The greater difficulty is that is relies on execution order. While
that isn't a problem in practice with the current implementation of
Gestalt, it probably will be in the future. So it becomes a problem of
whether the extension function can be defined in such a way as to
guaranteee the correct execution order (since
http://exslt.org/system/environment is already defined without any
such refinements, this might be difficult).
--
Colin Adams
Preston Lancashire

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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