OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]


Subject: Re: DOCBOOK-APPS: Stylesheet for remapping/renaming elements


> From: Michael Smith <smith@xml-doc.org>
> 
> Nik Clayton mentioned a way to remap DocBook elements to other element
> names -- that is, to take something like this:
> 
>   <helpproject status="draft" remap="article">
>        ...
>     <topic revisionflag="changed" remap="section">
>         ...
>     </topic>
>   </helpproject>
> 
> and turn it into this:
> 
>   <article status="draft">
>        ...
>     <section revisionflag="changed">
>         ...
>     </section>
>   </article>
>       
> Here's a simple stylesheet that I think will do it.
> 
>   <?xml version='1.0'?>
>   <xsl:transform 
>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
> 
>   <!-- ********************************************************************
>        Use the "attributename" parameter to specify the attribute
>        that holds the names of the elements you want to rename to.    
>                                                                             -->
> 
>     <xsl:param name="attributename">remap</xsl:param>
> 
> 
>   <!-- ********************************************************************
>        Look for any elements with an attribute named $attributename and
>        replace the name of the element with the value of that attribute
>                                                                             -->
> 
>     <xsl:template match="node()|@*">
>       <xsl:choose>
> 
>         <xsl:when test="@*[local-name()=$attributename]">
>           <xsl:element name="{@*[local-name()=$attributename]}">
>             <xsl:apply-templates
>                  select="@*[local-name()!=$attributename]|node()"/>
>           </xsl:element>
>         </xsl:when>
> 
>         <xsl:otherwise>
>           <xsl:copy>
>             <xsl:apply-templates select="@*|node()"/>
>           </xsl:copy>
>         </xsl:otherwise>
> 
>       </xsl:choose>
>     </xsl:template>
>   </xsl:transform>
> 
> 
> To make the best use of it, you'd also want to do some steps to add
> support for it in your DTD customization layer:
> 
>  1. Decide on an attribute to use throughout the customization layer
>     for storing the element names you want to convert/rename to.
>     Off the shelf, the stylesheet defaults to looking for "remap".
> 
>  2. Add the attribute name to the ATTLIST for each new element in your
>     customization layer, as an NMTOKEN with a #FIXED value.
> 
>     If you're creating a DocBook customization layer, you'd end up
>     with an ATTLIST that looked something like this:
> 
>     <!ATTLIST  helpproject
>                        remap    NMTOKEN      #FIXED     "article"
>                        appid    CDATA        #IMPLIED
>                        %label.attrib;
>                        %status.attrib;
>                        %id.attrib;
>                        %lang.attrib;
>                        %xreflabel.attrib;
>                        %revisionflag.attrib;
>                        %effectivity.attrib;
>                        %local.common.attrib;
>                        %helpset.role.attrib;
>                        %local.helpset.attrib;
>     >
> 
> If you do that, you don't have to include "remap" attributes in your
> document instances. But your XSLT engine will need access to your
> customization layer DTD; you won't be able to correctly process a
> document if it doesn't include a DOCTYPE declaration that references
> your customization-layer DTD where the #FIXED attributes are declared.
> 
> This might not seem like a proper use of "remap", but I think Eve
> Maler and Jeanne El Andaloussi's "Developing SGML DTDs: From Text to
> Model to Markup" provides some support for using it that way.
> 
> They discuss a "remap" attribute in that book (Conversion Markup
> section (8.4.2) of the Markup Model Design and Implementation chapter)
> and outline a couple different things it might be used for, including
> "transforming SGML documents to conform to a different DTD (or to the
> same DTD but with different or augmented contents)."

Clearly the remap attribute is intended to capture
the former element name for a transformed element
so that something special can be done with it.
Your concern about proper use of remap comes from the phrase
"previous markup scheme" in the description of
the attribute in the Definitive Guide.  You are
using remap essentially for the "next markup scheme" instead
of previous, right?

Well, consider modifying your transformation to make it
round trip.  Change your stylesheet to add a remap
attribute to your generated Docbook elements to indicate
which help element they came from.  Then you can write the
reverse stylesheet that transforms a Docbook document back
to the help customization.  It reads the remap value of a
Docbook element to decide which help element to create, and
adds a remap value to indicate which Docbook element it
came from.  That makes the Docbook element name
"previous".  Even if you don't actually perform the reverse
transformation, you have defined it and therefore can use
remap as you have described, in a virtual sense.  The
documents are isomorphic, remapping to each other.

There, feel better?  8^)

Anyway, I think it would be useful for your transformation
to capture which help element it came from in case some
special handling is desired.  Who knows, there may
be cases where you need to do the reverse transformation.
Consider the initial conversion of an existing DocBook
document to a help document, for example.

bobs
Bob Stayton                                 400 Encinal Street
Publications Architect                      Santa Cruz, CA  95060
Technical Publications                      voice: (831) 427-7796
Caldera International, Inc.                 fax:   (831) 429-1887
                                            email: bobs@caldera.com


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]


Powered by eList eXpress LLC