[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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" 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|