xsl-list
[Top] [All Lists]

RE: [xsl] How can one get the name of a template or function?

2013-02-28 21:50:53
I'm resurrecting an old 2009 topic regarding
getting the name of a template.

I followed Michael's suggestion below and have
successfully written an extension function that
produces the names of the template in instances
where the template is invoke through the
xsl:call-template mechanism.

I'd be happy to provide a how-to on how I accomplished this along with
demonstration files if someone would like them; I suspect this is a
very esoteric area and there would not be any takers on my offer.

What I would like to have is the ability to get
the name of a template in instances where the
template is invoked via the match mechanism:
xsl:apply-templates.  This would be for instances where
the template has a name attribute, e.g. name="template_ABC".  I tried
invoking my function similar to that below in a match situation and
null was returned despite the fact that the template that matched had
a name attribute.

Any suggestions on how to approach this?  I'm new to studying the
internals of Saxon, but believe there must be some place where
information about the templates is stored to be accessed by the parser
for the match facility and that extending the properties of the
storage model to include a name attribute in instances where a
template does have a name attribute would be the way toapproach this.
Maybe I'm barking up the wrong tree and the matching mechanism is not
what I'm imagining?

Thanks,

John Poole


here's the message I'm following up on:

On 2009-02-11 11:57:49  Michael Kay posted to this list:

If you're prepared to grovel around the depths of Saxon internals, you can
write an extension function


public static String getTemplateName(net.sf.saxon.expr XPathContext context)
{
     try {
        return context.getOrigin().getObjectName().getDisplayName();
     } catch (Exception err) {
        return null;
     }
}

and call it without any arguments as xx:getTemplateName(). Not tested. It
will only give the template name if it was invoked using call-template.
Should probably work for function calls as well.

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

<Prev in Thread] Current Thread [Next in Thread>