[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

variables vs. modes

Subject: variables vs. modes
From: Bruce D'Arcus <bdarcus@xxxxxxxxxxxxx>
Date: Thu, 25 Nov 2004 17:02:33 -0500
raw mods
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[@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="{@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>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.