You need to make it an explicit parameter
 
<xsl:function name="f:count-ancestors" as="xs:integer">
  <xsl:param name="target" as="node()"/>
  <xsl:sequence select="count($target/ancestor::node())"/>
</xsl:function>
 
then:
 
<xsl:value-of select="f:count-ancestors(.)"/>
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of martin.me.roberts@bt.com
Sent: 19 March 2008 17:05
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Context in xsl functions

Hi,
  I was hoping to tidy up my code by using functions instead of named templates,  however one of the named templates uses the ancestor:: call and so I need the context.  Is there any way of passing this into a function?
 
martin