[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Name of current mode

Subject: Re: Name of current mode
From: Tony Graham <Tony.Graham@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 19 Apr 2010 17:10:55 +0100
Re:  Name of current mode
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="http://www.w3.org/1999/XSL/Transform"
  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   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.