[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: [xslt 2.0] Difference betwen functions and templat

Subject: Re: [xslt 2.0] Difference betwen functions and templates
From: "Abel Braaksma (online)" <abel.online@xxxxxxxxx>
Date: Thu, 19 Jul 2007 17:25:59 +0200 (CEST)
Re:  [xslt 2.0] Difference betwen functions and templat
>> <!-- output will then be -->
>> mod:dog: Bark! I am a dog
>> mod:cat: Meow! I am a cat
>
> Not quite - that should really be "mod:animal::say-name()" called
> twice to be polymorphism - you're calling the "concrete" method
> there rather than the abstract.

Uhuh, bad example.... I should actually have a list of mod:animal
which contains both cats and dogs. Then loop the list and call the
fu:say-name() method. Then it would resemble the OO paradigm better.

>
> So why is this polymorphism?  Because the common Animal.xslt will
> use the $name variable depending on how the transform was
> constructed. You call "sayName" in the Animal stylesheet and that
> uses the $name variable in the Dog/Cat stylesheet.

I see what you mean and yes, i agree on that it is a (basic form of)
polymorphism.

>
> The Animal stylesheet is kind-of abstract in that it won't run on
> it's own because it lacks a declaration for $name.
>

That is indeed the way I use it now, especially in browser based
XSLT 1.0 (not sure why I encounter it less with XSLT 2.0 on the
server side).

To follow-up on your example using variables, i tend to use the
following construction when I *do* use it with XSLT 2.0 (not avail.
in 1.0). This raises an error when you fail to 'overload' the
variable in your importing stylesheet:

<!-- animal.xslt -->
<xsl:param name="name" required="yes" />

at least you get an error if the dog.xslt or cat.xslt (i.e., the
concrete 'classes' derived from this 'abstract' one) do not specify
the $name parameter. Even better, I use a variable instead as a
'best practice', because the param should not be settable or visible
from the outside (information hiding, haha):

<!-- dog.xslt -->
<xsl:variable name="name" select=" 'dog' " />


Cheers,
-- Abel Braaksma

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.