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="http://www.w3.org/1999/XSL/Transform" xmlns:mode="mode" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="mode xs" version="2.0"> <xsl:template match="image"> <xsl:apply-templates select="." mode="captioned-image"/> <xsl:apply-templates select="." mode="block-image"/> </xsl:template> <xsl:template match="image" mode="captioned-image block-image"> <xsl:variable name="mode" as="xs:string"> <xsl:call-template name="mode:get-name"/> </xsl:variable> <xsl:choose> <xsl:when test="$mode eq 'captioned-image'">captioned-image</xsl:when> <xsl:when test="$mode eq 'block-image'">block-image</xsl:when> <xsl:otherwise> <xsl:message>Other</xsl:message> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="mode:get-name" as="xs:string"> <xsl:variable name="mode:bogus" as="element()"> <mode:bogus/> </xsl:variable> <xsl:apply-templates select="$mode:bogus" mode="#current"/> </xsl:template> <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> </xsl:template> </xsl:stylesheet> ------------------------------------------------------------ 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). Regards, 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Name of current mode, Dave Pawson | Thread | Re: [xsl] Name of current mode, Wendell Piez |
Re: [xsl] how to decode Base64 in X, Ivan Shmakov | Date | Re: [xsl] Name of current mode, Wendell Piez |
Month |