Re: [xsl] Name of current mode

Subject: Re: [xsl] Name of current mode
From: Tony Graham <Tony.Graham@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 19 Apr 2010 17:10:55 +0100
On Mon, Apr 19 2010 14:28:14 +0100, gkholman@xxxxxxxxxxxxxxxxxxxx wrote:
> At 2010-04-19 14:24 +0200, Christian Roth wrote:
>>is there an accessor function for the current mode in XSLT 2?
> No, but when I've wanted to do this I've used tunnel parameters.

Here's an alternative that doesn't need anything at the (possibly many)
places where you change the mode, but at the cost of being more verbose
where you test the mode:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="";
  exclude-result-prefixes="mode xs"

  <xsl:template match="image">
    <xsl:apply-templates select="." mode="captioned-image"/>
    <xsl:apply-templates select="." mode="block-image"/>

  <xsl:template match="image" mode="captioned-image block-image">
    <xsl:variable name="mode" as="xs:string">
      <xsl:call-template name="mode:get-name"/>

      <xsl:when test="$mode eq 'captioned-image'">captioned-image</xsl:when>
      <xsl:when test="$mode eq 'block-image'">block-image</xsl:when>

  <xsl:template name="mode:get-name" as="xs:string">
    <xsl:variable name="mode:bogus" as="element()">
    <xsl:apply-templates select="$mode:bogus" mode="#current"/>

  <xsl:template match="mode:bogus" mode="captioned-image">captioned-image</xsl:template>
  <xsl:template match="mode:bogus" mode="block-image">block-image</xsl:template>
  <xsl:template match="mode:bogus" mode="#all" priority="-1">
    <xsl:message>No match</xsl:message>
    <xsl:text>no match</xsl:text>

Tested with the document '<image/>'.

I came up with this before I read the whole of the thread, and having
checked that it's already been said, I think the <xsl:next-match> idea
providid by Gerrit Imsieke is probably the neatest solution (if you're
up to subdividing the processing that way, that is).


Tony Graham                         Tony.Graham@xxxxxxxxxxxxxxxxxxxxxx
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd                               XML Guild member
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                     
xslide Emacs mode        
Unicode: A Primer                               urn:isbn:0-7645-4625-2

Current Thread