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

RE: design question on function namespaces

Subject: RE: design question on function namespaces
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 3 May 2005 14:42:26 +0100
polymorphism xslt
> Yes, I understand this.  But say you want to implement a function for 
> your "does this chapter have any footnotes" example, but you 
> deal with 
> DocBook NG, TEI 5 and OpenOffice.  Would you reimplement the function 
> three times, or would there be a way to make it generic so that it 
> could be reused across the different document types and 
> namespaces.  If 
> you do the former, then they're not THAT reusable.
> 

If the implementation in the three cases is completely different, but you
want the user to make the same call in each case, then you need to implement
the polymorphism yourself behind a wrapper interface. 

Of course polymorphism in XSLT means apply-templates...

So you could define

function name="doc:chapter-has-footnotes"
  xsl:param name="chapter"
  xsl:apply-templates select="chapter" mode="doc:chapter-has-footnotes"
/function

and then implement a template in this mode for each of the different
document types

It's easy to forget that in 2.0 a template can return a boolean:

<xsl:template match="open-office:chapter" mode="doc:chapter-has-footnotes"
as="xs:boolean">
  <xsl:sequence select="exists(.//footnote)"/>
</xsl:template>

Just a thought, there are many ways to organise this.

Michael Kay
http://www.saxonica.com/

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-2013 All Rights Reserved.