xsl-list
[Top] [All Lists]

variables vs. modes

2004-11-25 15:02:33
I'm considering reworking my (2.0) stylesheets towards greater reliance on global variables.

In my current approach, I use multiple passes, with multiple modes. However, I feel that it may make more sense (be more flexible, easier to integrate with other stylesheets and to maintain, etc.) to use variables instead. Below is a simple example of what I mean.

Are there any counter-arguments I may be missing before I actually do this?

Bruce

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0"
   xmlns:mods="http://www.loc.gov/mods/v3";
   xmlns:db="http://docbook.org/docbook-ng";
   xmlns:exist="http://exist.sourceforge.net/NS/exist";
   exclude-result-prefixes="db mods exist">

   <xsl:output method="xml" encoding="utf-8" indent="yes"/>

<!-- grab all the citation pointers -->
   <xsl:variable name="citerefs" select="//db:biblioref/@linkend"/>

<!-- construct a list of unique references to pass to a query -->
   <xsl:variable name="citekeys">
     <xsl:text>(</xsl:text>
       <xsl:for-each-group select="$citerefs" group-by=".">
         <xsl:if test="position() &gt; 1">,%20</xsl:if>
         <xsl:text>'</xsl:text>
         <xsl:value-of select="."/>
         <xsl:text>'</xsl:text>
       </xsl:for-each-group>
     <xsl:text>)</xsl:text>
   </xsl:variable>

<!--
take list of references, and grab them from a database over http; in this case it's an XQuery to eXist,
but it should be parameterized for flexibility
-->
   <xsl:variable name="bibrecord"
        select='doc(concat("http://localhost:8080/exist/servlet/db/biblio?";,
                
"_query=declare%20namespace%20mods=%22http://www.loc.gov/mods/v3%22;";,
                "%20for%20$citekey%20in%20",
                        $citekeys,
                "%20return%20/mods:modsCollection/mods:mods[(_at_)ID=$citekey]"))' 
/>
<!--
create raw bib collection; in a real implementation, this might be where
enhancement (grouping, sorting, adding content for processing, etc.) would take place
-->
   <xsl:variable name="raw-biblist">
     <mods:modsCollection>
       <xsl:copy-of select="$bibrecord/exist:result/mods:mods" />
     </mods:modsCollection>
   </xsl:variable>

<!-- take raw biblist and format it -->
   <xsl:variable name="formatted-biblist">
     <xsl:for-each select="$raw-biblist/mods:modsCollection/mods:mods">
       <p id="{(_at_)ID}">
         <xsl:apply-templates select="mods:titleInfo"/>
       </p>
     </xsl:for-each>
   </xsl:variable>

   <xsl:template match="/">
     <div id="bibliography">
       <xsl:copy-of select="$formatted-biblist"/>
    </div>
   </xsl:template>

   <xsl:template match="mods:titleInfo">
     <span class="title">
       <xsl:apply-templates select="mods:title"/>
       <xsl:apply-templates select="mods:subTitle"/>
     </span>
   </xsl:template>

   <xsl:template match="mods:title">
     <xsl:value-of select="."/>
   </xsl:template>

   <xsl:template match="mods:subTitle">
     <xsl:text>: </xsl:text>
     <xsl:value-of select="."/>
   </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>