This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Call context within a named xsl:template
- From: Robert Stuart <Robert dot Stuart at NFER-NELSON dot co dot uk>
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 15 Nov 2001 09:07:27 -0000
- Subject: RE: [xsl] Call context within a named xsl:template
- Reply-to: xsl-list at lists dot mulberrytech dot com
No, but you can validate parameters - which, in turn, can be used to force
calling templates to give some kind of context.
(Standard caveats regarding debugging apply.)
Something like this:
###############
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<!-- a template with a required parameter -->
<xsl:template name="called">
<xsl:param name="caller"/>
<!-- the interesting bit -->
<xsl:if test="not( $caller )
and not( caller = '0' )
and not( caller = 'false' ) ">
<xsl:message terminate="yes">
<xsl:text>No caller given</xsl:text>
</xsl:message>
</xsl:if>
<!-- end the interesting bit -->
<!-- the rest of the template -->
<b>Called by: <xsl:value-of select="$caller"/></b><br />
</xsl:template>
<xsl:template match="/">
<xsl:call-template name="called">
<xsl:with-param name="caller" select="'one'"/>
</xsl:call-template>
<xsl:call-template name="called">
<xsl:with-param name="caller" select="'1'"/>
</xsl:call-template>
<xsl:call-template name="called">
<xsl:with-param name="caller" select="'0'"/>
</xsl:call-template>
<xsl:call-template name="called">
<xsl:with-param name="caller" select="'false'"/>
</xsl:call-template>
<!--
the following fails
in my test environment, nothing but the "No caller given" message
appeared
-->
<!--
<xsl:call-template name="called">
</xsl:call-template>
-->
</xsl:template>
</xsl:stylesheet>
###############
Cheers
Robert Stuart
======================================
Date: Wed, 14 Nov 2001 08:45:18 +0100
From: Ruben.Provoost@mediamine.com
Subject: RE: [xsl] Call context within a named xsl:template
On 13 Nov 2001, at 18:06, Michael Kay wrote:
> > Is
> > there anyway I can determine who called me?
> >
> No.
>
> (It's surprising how often people ask for features in XSLT that I've never
> come across in any other programming language...)
I've seen (NOT written...) Java code like this :
public void someMethod()
{
[snip]
Ruben Provoost
[snip]
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list