RE: [xsl] push-pull

Subject: RE: [xsl] push-pull
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 19 Mar 2008 12:44:28 -0400
Hi,

At 05:16 AM 3/19/2008, Mike wrote:
>
> What is the best way for an xslt2 template declared like
> this, for example:
> <xsl:template name="pull" match="*" mode="push">...
> to know or recognize when it is pulled or pushed.
> (called by name or invoked by match and mode)?
>

I don't think you can.

You could, however, fake it:


<xsl:template name="pull" match="*" mode="push">
  <xsl:param name="pulled" select="false()"/>
  <xsl:if test="$pulled">...</xsl:if>
...

and then pass in a value of true() whenever pulling.

I've never been convinced it's a good idea to have such templates: it's hard
to make sure that the entry conditions are the same whether it is invoked by
apply or by call. In particular, when you are writing a match template it
should be possible to assume that the context item matches the pattern, and
allowing entry by name makes this assumption invalid.

I agree that it is probably not such a great idea. I have had occasion to do it, but it's also been suggested to me that in such a case, an extra step of indirection to avoid it would make the traversal much clearer (as Mike also suggests) and maintenance easier. So I might have changed my mind.


And in this case, the very fact that you need to test which way the template was entered suggests it's not such a great idea.

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread