RE: [xsl] design question on function namespaces

Subject: RE: [xsl] design question on function namespaces
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 3 May 2005 14:42:26 +0100
> 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