xsl-list
[Top] [All Lists]

RE: design question on function namespaces

2005-05-03 06:42:26
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/



--~------------------------------------------------------------------
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>
--~--