xsl-list
[Top] [All Lists]

Re: temp trees and context switching

2004-11-13 21:27:45

On Nov 12, 2004, at 7:31 PM, Bruce D'Arcus wrote:

Below is my first few templates (I can't post the entire code), with source example below it. Am I doing something wrong with using the call-template below?

I'm not sure this is the best solution (any comments?), but I ended up adding another pass to the processing, since I couldn't get it work just using the call-template:

<?xml version="1.0" encoding="utf-8"?>
<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:bib="http://xbiblio.sourceforge.net";
        xmlns="http://docbook.org/docbook-ng";
        exclude-result-prefixes="mods bib db xs">

<!--
This driver file creates a temporary tree of the document for
subsequent processing. In the case of footnote class
citations, this means wrapping all citations in a footnote
element.
-->

<xsl:key name="citekey" match="db:biblioref/@linkend" use="'all'" />

<!-- first create a temporary tree that adds the raw bibliographic data based on citations -->
  <xsl:template match="/">
    <xsl:variable name="temp">
      <xsl:apply-templates mode="create-bibcollection" />
    </xsl:variable>
    <xsl:apply-templates select="$temp" mode="step-2" />
  </xsl:template>

  <xsl:template match="db:article" mode="create-bibcollection">
    <article>
      <xsl:apply-templates mode="create-bibcollection" />
    </article>
  </xsl:template>

  <xsl:template match="db:info" mode="create-bibcollection">
    <xsl:copy-of select="."/>
  </xsl:template>

  <xsl:template match="db:section" mode="create-bibcollection">
    <xsl:copy-of select="."/>
  </xsl:template>

<!-- next take that tree and create another temporary tree enhanced for subsequent processing -->
  <xsl:template match="/" mode="step-2">
    <xsl:variable name="temp">
      <xsl:apply-templates mode="enhanced-bib" />
    </xsl:variable>
    <xsl:apply-templates select="$temp" mode="modified" />
  </xsl:template>

  <xsl:template match="db:article" mode="enhanced-bib">
    <article>
      <xsl:apply-templates mode="enhanced-bib" />
    </article>
  </xsl:template>

  <xsl:template match="db:info" mode="enhanced-bib">
    <xsl:copy-of select="."/>
  </xsl:template>

<xsl:template match="db:section[$citation-class='author-year']" mode="enhanced-bib">
    <xsl:copy-of select="."/>
  </xsl:template>

  <xsl:template match="db:bibliography" mode="create-bibcollection">
    <bibliography>
      <modsCollection xmlns="http://www.loc.gov/mods/v3";>
        <xsl:for-each select="distinct-values(key('citekey', 'all'))">
          <xsl:variable name="bibrecord"
select="doc(concat('/Users/darcusb/Desktop/xbiblio-alt/samples/bib- data/', ., '.mods'))/mods:modsCollection/mods:mods"/>
          <xsl:copy-of select="$bibrecord" />
        </xsl:for-each>
      </modsCollection>
    </bibliography>
  </xsl:template>

  <xsl:template match="db:bibliography" mode="enhanced-bib">
    <bibliography>
<xsl:apply-templates select="mods:modsCollection" mode="enhanced-bib"/>
    </bibliography>
  </xsl:template>

<xsl:template match="db:section[$citation-class='note']" mode="enhanced-bib">
    <section>
      <xsl:apply-templates mode="enhanced-bib"/>
    </section>
  </xsl:template>

<xsl:template match="db:section[$citation-class='note']/db:info" mode="enhanced-bib">
    <xsl:copy-of select="."/>
  </xsl:template>

<xsl:template match="db:footnote[$citation-class='note']" mode="enhanced-bib">
    <footnote>
      <xsl:apply-templates mode="enhanced-bib"/>
    </footnote>
  </xsl:template>

<xsl:template match="db:section/db:para[$citation-class='note']" mode="enhanced-bib">
    <para>
      <xsl:apply-templates mode="enhanced-bib"/>
    </para>
  </xsl:template>

<xsl:template match="db:footnote/db:para[$citation-class='note']" mode="enhanced-bib">
    <para>
      <xsl:apply-templates mode="enhanced-bib"/>
    </para>
  </xsl:template>

<xsl:template match="db:citation[$citation-class='note']" mode="enhanced-bib"> <!-- with footnote class citations, wrap all citations in a footnote, unless
already in a footnote -->
    <xsl:choose>
      <xsl:when test="ancestor::db:footnote">
        <xsl:copy-of select="."/>
      </xsl:when>
      <xsl:otherwise>
        <footnote>
          <xsl:copy-of select="."/>
        </footnote>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>