Subject: Attributes, modes and templates From: Alex Lancaster <alex@xxxxxxxxxxx> Date: 27 Apr 2000 04:14:12 -0600 |
XSLers, As an old DSSSL-smith, and now an XSL newbie, I'm trying to adapt my old DSSSL stylesheets to use XSL. I am new to the list, and I've working through the mail archives and the FAQs, and some posts have come close to asking this question, and talk about the issues involved, but not quite so directly, so I thought I'd risk posting to the list myself. Apologies in advance if this is indeed a FAQ. In particular I'm having having some difficulty making XSL work (at least vaguely) analogously to how I am used to doing it in DSSSL when customizing Norm Walsh's XSL stylesheets for the DocBook DTD using the `role' attribute. [NB: Although I'm using these particular XSL stylesheets and the DocBook DTD, I think the information I'm presenting should not require any special knowledge of these stylesheets]. [I'm also using XT version 19991105]. [and I'm using 1.9 version of the XSL DocBook stylesheets.] Here's a self-contained testcase, test.xml: <!DOCTYPE article PUBLIC "-//Norman Walsh//DTD DocBk XML V3.1.7//EN" "/opt/src/alex/src/docbook/xml-dtd-3.1.7/docbookx.dtd"> <article> <title>Test page</title> <variablelist> <varlistentry> <term>Regular 'ole list</term> <listitem> <para>Nothin' interesting here...</para> </listitem> </varlistentry> </variablelist> <para>---------------------------------------------------</para> <variablelist role="programmers"> <varlistentry> <term> <corpauthor>Big Corp DotCom, I should be specially formatted!</corpauthor> </term> <listitem> <para>Members of consulting team doing nothing at all for vast sums of money... </para> </listitem> </varlistentry> </variablelist> </article> I have two VARIABLELISTs in this document. The first is a `vanilla' one, i.e. it should be treated as per Norm Walsh's stock XSL stylesheets. In the second when the `role' attribute of VARIABLELIST is set to `programmers', I want to be able to customize *some* children of the VARIABLELIST node, to do something special (i.e. different from the stock), but I want to have the rest handled as per the stock stylesheets. 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> [I modelled this somewhat on titlepage.xsl in the docbook XSL 1.9 distribution, just FYI]. 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. [I can send URLs to the resulting HTML files, on request -- trying to save bandwidth on the list...] The only obvious way out would be to create templates with a `match' for _every_ tag in the (mode="programmer-info-mode"), but that seems time-consuming, error-prone, not too mention, ugly. >From my limited understanding of XSL/XSLT I thought that I could use the wildcard for all the default cases (within a `mode'), and then specify only the variant individual cases which I want to do something special on (within that `mode'), but it doesn't seem necessarily so. For DSSSLers who also know XSL, essentially what I want to do, above, can be represented by a custom DSSSL stylesheet (quite elegantly) as: (element variablelist (let ((role (attribute-string (normalize "role")))) (if (equal? role "programmers") (with-mode programmer-info-mode (process-children)) (process-children)))) (mode programmer-info-mode (element corpauthor (make sequence ($bold-italic-seq$ (literal "Group: ")) (process-children))) ) Does anybody know if there is an equivalent way in XSL to do (roughly) the same thing, that doesn't involve coding explicit cases for each of the matching elements that might occur inside a mode? Cheers, Alex -- Alex Lancaster * alex@xxxxxxxxxxx * www.santafe.edu/~alex * 505 984-8800 x242 Santa Fe Institute (www.santafe.edu) & Swarm Development Group (www.swarm.org) XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: How to output comments in HTML, Kay Michael | Thread | Re: Attributes, modes and templates, Wendell Piez |
How to output comments in HTML, Hakan Pettersson | Date | RE: Simple Problem, Ben Robb |
Month |