[xsl] design question on function namespaces

Subject: [xsl] design question on function namespaces
From: Bruce D'Arcus <bdarcus@xxxxxxxxx>
Date: Tue, 3 May 2005 07:16:19 -0400
I've modiified a lot of my code and moved much of the logic into functions. For example:

  <xsl:function name="mods:year">
    <xsl:param name="bibref" as="element(mods:mods)"/>
    <xsl:for-each select="$bibref">
      <xsl:value-of  select="substring((mods:originInfo/mods:dateIssued,
			mods:relatedItem/mods:originInfo/mods:dateIssued,
			mods:relatedItem/mods:part/mods:date)[1],1,4)" />
    </xsl:for-each>
  </xsl:function>

Because XSLT 2.0 and XQuery share the same data model (XPath 2.0), it's easy to convert between them. Here's the equivalent function in the eXist XML DB bibliographic example (which I use; I modified this function to match the logic of my XSLT one):

declare function display:year($rec as element()) as xs:string? {
       substring(($rec/mods:originInfo/mods:dateIssued,
       $rec/mods:relatedItem/mods:originInfo/mods:dateIssued,
       $rec/mods:relatedItem/mods:part/mods:date)[1],1,4)
};

I think based on this, I'm going to try where possible to have logic defined in functions, and in xpath (2.0) rather than pure XSLT.

One design question: Mike Kay in his book on XSLT 2.0 advocates function namespaces based on the namespace of the data they work on.

I ask because I'd like to keep the option open later to support formats in other namespaces. So does this suggest using a namespace that refers to the function rather than the input namespace?

Bruce

Current Thread