xsl-list
[Top] [All Lists]

Re: dynamically applying templates

2004-09-15 11:05:18
Hi again Bruce,

Okay, see comments below....

At 01:14 PM 9/15/2004, you wrote:

==== config ====
<citationstyle xmlns="http://xbiblio.sourceforge.net/xcs";>
<content>
<bibliography author-as-sort-order="yes">
  <entry>
    <reftype name="book">
      <title font-style="italic" after=", "/>
      <creator/>
    </reftype>
  </entry>
</bibliography>
</content>
<citationstyle>

==== source ====

<doc>
<!-- this would normally be docbook ng; but keep it simple for now -->
   <mods xmlns="http://www.loc.gov/mods/v3";>
     <name type="personal">
        <namePart type="given">Jane</namePart>
        <namePart type="family">Doe</namePart>
     </name>
     <titleInfo>
        <title>Main Title</title>
        <subTitle>Subtitle</subTitle>
     </titleInfo>
   </mods>
</doc>

==== xsl ====

<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:xs="http://www.w3.org/2001/XMLSchema";
                xmlns:db="http://docbook.org/docbook-ng";
                xmlns:mods="http://www.loc.gov/mods/v3";
                xmlns="http://www.w3.org/1999/xhtml";
                xmlns:bib="http://xbiblio.sourceforge.net/xbib";
                xmlns:cs="http://xbiblio.sourceforge.net/xcs";
                exclude-result-prefixes="mods db bib xs cs">

<xsl:output method='xhtml' encoding='utf-8' indent='yes'/>

<xsl:strip-space elements="*"/>

<!-- read the external citation style file -->
<xsl:param name="citation-style" required="yes" as="xs:string" />

<xsl:variable name="styles" as="document-node()"
  select="doc(concat($citation-style, '.csl'))" />

<xsl:variable name="style-biblio" select="$styles/cs:citationstyle/cs:content/cs:bibliography"/>

<xsl:template match="/">
  <xsl:param name="source"/>

Since you're not going to pass a parameter into this template, the declaration is unnecessary.

  <html>
    <div>
      <xsl:apply-templates mode="bibliography">
        <xsl:with-param name="source" select="$style-biblio"/>
      </xsl:apply-templates>

Here you are applying templates to the child node of the root, namely 'doc' in the mods document. It has no matching template, so it defaults to apply templates to its children.

Its only child is mods:mods, which has no template in mode "bibliography", so it will fail to match. Likewise all the way down the tree.

Also, passing the config tree in as "source" makes no sense here. We aren't ready to jump to the config tree yet (and it won't be the source when we do, if we are considering "source" to be our incoming data
).

Accordingly, change this template to read:

<xsl:template match="/">
  <html>
    <div>
      <xsl:apply-templates/>
   </div>
  </html>
</xsl:template>

... and add a template to match mods:mods (but notice I pulled the mode, imagining that the "bibliography" mode is to handle nodes in the config document.

That's the template where we'll jump trees, so --

<xsl:template match="mods:mods">
<xsl:apply-templates select="$style-biblio/cs:entry/cs:reftype[(_at_)name='book']"
     mode="bibliography">
    <!-- of course the value 'book' should probably be parameterized -->
    <xsl:with-param name="source" select="."/>
    <!-- this is where we jump to the other tree, carrying the original
       context with us as the $source -->
  </xsl:apply-templates>
</xsl:template>

... see where that gets you ...

Also, a niggle: any particular reason why your configuration couldn't be

<bibliography author-as-sort-order="yes">
  <entry reftype="book">
    <title font-style="italic" after=", "/>
    <creator/>
  </entry>
</bibliography>

thereby making it a bit tighter and easier to handle?

The rest of the templates look fine.

I hope that helps,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
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
======================================================================