Subject: RE: [xsl] variables vs. modes From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Thu, 25 Nov 2004 23:47:10 -0000 |
I tend to use this approach quite heavily, of structuring the processing as a sequence of variables, each one of which is derived from the one before. It's like a miniature pipeline. Some people use the same technique but using local variables within a containing template, rather than using global variables. However, as soon as you have more than one step in your pipeline that can benefit from the flexibility of apply-templates, you need to think in terms either of multiple modes within a single stylesheet, or multiple stylesheets connected in a pipeline. Incidentally I've had some brief exposure recently to Orbeon as a pipeline processor for stringing together transformations, and it's well worth a look. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Bruce D'Arcus [mailto:bdarcus@xxxxxxxxxxxxx] > Sent: 25 November 2004 22:03 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] variables vs. modes > > 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() > 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] variables vs. modes, Bruce D'Arcus | Thread | [xsl] Template overriding problem w, Lee Kemp |
[xsl] variables vs. modes, Bruce D'Arcus | Date | [xsl] Template overriding problem w, Lee Kemp |
Month |