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: Only transform certain tags


> From: Claus Rasmussen <claus@arsdigita.com>
>
> I'm using DocBook 4.1.2 XML and Norm's associated style sheets.
> 
> I've extended the DTD with some custom sections and now I'm trying to hit
> valid docbook format from there. This means that I want only my custom
> <mysection> tag or whatever to be transformed (via a custom XSL style sheet
> that turn my custom-tags into docbook tags). So basically I want to have this:
> 
> <article>
> 
> <sect1>
> 
> ...
> 
> </sect1>
> 
> <mysection>
> 
>    ...
> 
> </mysection>
> 
> </article>
> 
> ..transformed into an article with, say, two sect1's. Basically I'm asking how
> I take non-matched tags and copy them and their content to the result tree.
> I've tried using <xsl:copy-of ... > but I can't have it catch only
> none-matched tags. Also, if I use regular <xsl:apply-templates/> I obviously
> only get the content of the foreign tags.
> 
> I'm sure this is easy, but could some one please give me a hint?

If I understand what you are trying to do,
I think you want to use <xsl:copy>, which is easier
to control since it doesn't copy all of its
children like <xsl:copy-of> does.

The stylesheet below will pass through everything,
except <mysection> elements are changed to <sect1>
elements.  Is that what you are after?

The first template replaces the
built-in default template rule with one that
copies elements rather than just copying text
nodes.  The second template has a more
specific match on "mysection", so it takes
precedence over the default and changes that element
to <sect1>.  The use of <xsl:copy-of select="@*"/>
in each template copies all the attributes of each
element through.


<?xml version='1.0'?>
<xsl:stylesheet
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
<xsl:output method="xml"/>

<xsl:template match="*|/">
        <xsl:copy>
                <xsl:copy-of select="@*"/>
                <xsl:apply-templates/>
        </xsl:copy>
</xsl:template>

<xsl:template match="mysection">
  <sect1>
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates/>
  </sect1>
</xsl:template>

</xsl:stylesheet>

You can add templates for any other elements
that need to be changed.  All unmatched elements
are matched by the first template.

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


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


Powered by eList eXpress LLC