[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: OOXML
> 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@xxxxxxxxxxxxxxxxxx> wrote: > > >>>>> "Colin" == Colin Paul Adams <colin@xxxxxxxxxxxxxxxxxx> writes: > > >>>>> "Alexander" == Alexander Johannesen <alexander.johannesen@xxxxxxxxx> writes: > Alexander> On Fri, Jun 27, 2008 at 21:58, John Snelson <john.snelson@xxxxxxxxxx> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|