Subject: Re: [xsl] Conditional text using attributes From: Michael Smith <smith@xxxxxxxxxxx> Date: 28 Dec 2000 15:48:32 -0800 |
Steve, I think the inner workings of the DocBook stylesheets are such that your example transform will perform as expected for conditionally including some elements, but not for others -- for example: <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"> <article> <articleinfo> <title os="PC">Starting the timer using Microsoft Windows</title> <title os="Mac">Starting the timer using MacOS</title> </articleinfo> <para>Press the...</para> </article> (I've included some expanded comments on that same example below, after quoting parts of the previous messages for context.) So instead of importing the DocBook templates, might it be possible instead to write a straight XML to XML "conditional inclusion" transform that will work with *any* well-formed XML document instance? What I mean specifically is a transform that: * conditionally includes elements based simply on attribute names/values, without regard at all for the actual element names * is a "standalone" transform that doesn't rely on importing other stylesheets that contain templates matching the element names Is that possible? How could it be expressed in XSLT? I think there's a great need for this kind of capability in the document-oriented XML world -- especially among documentation authors who have come to rely on the conditional text features in FrameMaker. --Mike Smith Comments on the DocBook case are after the following quoted sections. Beth Fischi <bfischi@xxxxxxxxxxxxx> writes: > I'm trying to figure out how to exclude text and graphics from an > output file (HTML or FO, for example) by testing for attributes in > my XSL stylesheet. For instance, I have an XML file with > instructions appropriate for both Macintosh users and Windows users. > > I'm using the DocBook DTD and Norm Walsh's DocBook XSL stylesheets Steve Muench <Steve.Muench@xxxxxxxxxx> writes: > [...] Let's say your Docbook source looks like this: > > <?xml version="1.0"?> > <article> > <para> > Press the <emphasis os="PC">Left</emphasis> mouse button to start > the timer. You can use the <emphasis os="Mac">Finder</emphasis> > <emphasis os="PC">Start Button</emphasis> to launch a new program. > </para> > </article> > > [...] we can create a "beth.xsl" stylesheet like the one below to > import the base stylesheet, and add one or more templates that will > take precedence over the templates from the imported stylesheet: > > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> > <xsl:import href="norm.xsl"/> > > <xsl:param name="os">Mac</xsl:param> > > <xsl:template match="*"> > <xsl:if test="not(@os) or @os=$os"> > <xsl:apply-imports/> > </xsl:if> > </xsl:template> > > </xsl:stylesheet> For certain instances, I don't think that transform will always work with the DocBook stylesheets as someone might expect. For example, suppose I want to supply alternate MacOS and PC titles for the "setting the timer" procedure: <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"> <article> <articleinfo> <title os="PC">Starting the timer using Microsoft Windows</title> <title os="Mac">Starting the timer using MacOS</title> </articleinfo> <para> Press the <emphasis os="PC">Left</emphasis> mouse button to start the timer. You can use the <emphasis os="Mac">Finder</emphasis> <emphasis os="PC">Start Button</emphasis> to launch a new program. </para> </article> ...and not that it matters in the case under discussion, but it is valid to have multiple DocBook <title> elements in an <articleinfo> section -- so the preceeding instance is not altogether artificial. If I run that instance through the transform method you've outlined, with no value specified for the $os parameter, it does not produce what I would expect. Specifically, I would expect the result to include the title with the os="Mac" attribute by default -- but it doesn't. Instead, it simply includes the first title, regardless of what attribute it has, and regardless of the value of the $os parameter. And although that one example may not be the best, there are other cases where a DocBook instance + standard DocBook stylesheet transform using that conditional inclusion method will not work. I'm noting this only to make the point that it in this case of conditional inclusion: * it seems problematic to rely on using templates that match specific element names * it would seem to be best to instead do a straight XML to XML transform based strictly on attribute names and values ...if that's even possible. There must be some way to express it in XSLT... -- Michael Smith mailto:smith@xxxxxxxxxxx XML-Doc http://www.xml-doc.org/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Conditional text using at, Steve Muench | Thread | Re: [xsl] Conditional text using at, Steve Muench |
RE: [xsl] Carrying Namespaces throu, Julian F. Reschke | Date | Re: [xsl] Conditional text using at, Steve Muench |
Month |