Subject: Re: Attributes, modes and templates From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Thu, 27 Apr 2000 11:46:44 +0100 |
Alex, I haven't tested this, but looking at your examples, I think the problem is in your wildcard template: > <!-- template (1) --> > <xsl:template match="*" mode="programmer-info-mode"> > <xsl:text>Running wildcard template for mode: </xsl:text><br/> > <xsl:apply-templates select="."/> > </xsl:template> What this template seems to be doing is putting out your tracing text, then processing the node again in the default mode. So any time the mode is invoked with the match not otherwise specified, it gets uninvoked. So the node with the mode calls the same node with no mode (sorry). This is overriding the default general match for elements in the mode, which would be: <xsl:template match="*" mode="programmer-info"> <xsl:apply-templates mode="programmer-info"> </xsl:template> One solution may be to change the wildcard template to a called template, like: <xsl:template name="programmer-info-mode-start"> <xsl:text>Starting processing in mode: </xsl:text><br/> <xsl:apply-templates select="." mode="programmer-info-mode"/> </xsl:template> Call this template using <xsl:call-template> instead of the <xsl:apply-templates mode="programmer-info-mode"/> in the calling template. Let the default for the mode stay the default (i.e. process children in the mode). Then you have to decide what you want to have happen with elements content called in the mode, but not in your special element. If it's just suppress it, one way would be to override the default template for text() in the mode, as in <xsl:template match="text()" mode="programmer-info"/> So text doesn't get output. If you do this, you'll need to change your second template to: <!-- template (2) --> <xsl:template match="corpauthor" mode="programmer-info-mode"> <strong><em> <xsl:text>Group: </xsl:text> </em></strong> <em><xsl:value-of select="."/></em> <!-- the preceding is the line I changed. --> </xsl:template> The crucial difference between XSL and DSSSL here is that in XSL, text nodes get output by default, whereas in DSSSL they don't. That's why this trickiness is necessary. There are other ways to do the same thing, such as an </xsl:apply-templates select=".//corpauthor"/> in a template matching VARIABLELIST (in the mode), in which case you wouldn't need to suppress text descendants.... which way is better, will depend. Either way avoids your basic problem of having to write a template for every node in the mode (which you correctly identified). Once you get everything working and don't need to trace, you can simplify this, possibly eliminating the step with the called template. The logic will actually end up being just like the DSSSL, although somewhat more verbose of course (and allowing for the caveat just stated). Good luck, Wendell Piez At 04:14 AM 4/27/00 -0600, you wrote: >My first cut implementation of this stylesheet is, test.xsl: > ><?xml version='1.0'?> ><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:html="http://www.w3.org/TR/REC-html40" > xmlns:xt="http://www.jclark.com/xt" > version="1.0" > exclude-result-prefixes="html" > extension-element-prefixes="xt"> > ><xsl:include href="/opt/src/alex/src/docbook/xsl-1.9/xhtml/xtchunk.xsl"/> > > <xsl:template match="variablelist"> > <xsl:choose> > <xsl:when test="@role='programmers'"> > <xsl:apply-templates mode="programmer-info-mode"/> > </xsl:when> > <xsl:otherwise> > <xsl:text>Applying imports:</xsl:text><br/> > <xsl:apply-imports/> > </xsl:otherwise> > </xsl:choose> > </xsl:template> > > <!-- template (1) --> > <xsl:template match="*" mode="programmer-info-mode"> > <xsl:text>Running wildcard template for mode: </xsl:text><br/> > <xsl:apply-templates select="."/> > </xsl:template> > > <!-- template (2) --> > <xsl:template match="corpauthor" mode="programmer-info-mode"> > <strong><em> > <xsl:text>Group: </xsl:text> > </em></strong> > <em><xsl:apply-templates mode="programmer-info-mode"/></em> > </xsl:template> > ></xsl:stylesheet> >Unfortunately when I process this document, template (2) never gets >called, and so I never get the special markup I want for the >CORPAUTHOR tag. > >If I comment out (1), then I get the special formatting I need, but >the rest of the text becomes inline, with no formatting at all. > >Catch 22. ... ====================================================================== 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 ====================================================================== XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Attributes, modes and templates, Alex Lancaster | Thread | Re: Attributes, modes and templates, Alex Lancaster |
RE: display in a recursive way, Paulo Gaspar | Date | Microsot parser is OK (Was: Re: Cop, Nikolai Grigoriev |
Month |