here's what I'm thinking (exploiting variables)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

here's what I'm thinking (exploiting variables)

Bruce D'Arcus
cc-ing in case you're not on the list yet David ...

OK, I was just experimenting with the approach that I think may make
more sense, which is to use variables apart from the main document
rather than passing around everything from tree to tree over multiple
passes (as I do in the current version).

Here's a simple example:

<?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>

Result:

<?xml version="1.0" encoding="UTF-8"?>
<div id="bibliography">
    <p id="Thrift1990a">
       <span class="title">For a New Regional Geography 1</span>
    </p>
    <p id="Tilly2000a">
       <span class="title">Review of Moral Economy and Popular
Protest</span>
    </p>
    <p id="TimesP2001a">
       <span class="title">Senators Stamp OK on Anti-Terrorism
Laws</span>
    </p>
    <p id="Veer1996a">
       <span class="title">Riots and Rituals: The Construction of
Violence and Public Space in Hindu Nationalism</span>
    </p>
</div>

So my thought is that somehow we create the following variables (which
are, of course, temporary trees):

        - citekeys (the ids for the references in the document)
        - raw-biblist (raw mods content constructed based on $citekeys)
        - intermediate-biblist (intermediate bibliography created from
$raw-biblist)
        - rendered-biblist (formatted bibliography created from
$intermediate-biblist, using a simple output driver)
        - intermediate-citations (intermediate citations, created from
$raw-biblist; can include first and subsequent, etc.)
        - rendered-citations (rendered citations, created from
$intermediate-citations, using a simple output driver)

It certainly seems cleaner.  Am hoping it's also at least as fast; if
not faster (though this stylesheet is seeming slow on my iBook right
now).  Features are essential, but performance is nice too!

This would involve simplifying the driver structure I have now, and
probably moving the current class-parameter-conditioned mods:mods
templates into variables.

BTW, I'm also hoping this approach makes more sense in the context of
apps like Word and OOo.

What do you think? Would this actually work?

Bruce



Reply | Threaded
Open this post in threaded view
|

Re: here's what I'm thinking (exploiting variables)

M. David Peterson
Bruce D'Arcus wrote:

>
>
> So my thought is that somehow we create the following variables (which
> are, of course, temporary trees):
>
>     -    citekeys (the ids for the references in the document)
>     -    raw-biblist (raw mods content constructed based on $citekeys)
>     -    intermediate-biblist (intermediate bibliography created from
> $raw-biblist)
>     -    rendered-biblist (formatted bibliography created from
> $intermediate-biblist, using a simple output driver)
>     -    intermediate-citations (intermediate citations, created from
> $raw-biblist; can include first and subsequent, etc.)
>     -    rendered-citations (rendered citations, created from
> $intermediate-citations, using a simple output driver)
>
> It certainly seems cleaner.  Am hoping it's also at least as fast; if
> not faster (though this stylesheet is seeming slow on my iBook right
> now).  Features are essential, but performance is nice too!
>
> This would involve simplifying the driver structure I have now, and
> probably moving the current class-parameter-conditioned mods:mods
> templates into variables.
>
> BTW, I'm also hoping this approach makes more sense in the context of
> apps like Word and OOo.
>
> What do you think? Would this actually work?


Looks good to me.  As soon as things clear out a bit more I will start
at the beginning and run through all of this and see if there are any
additional comments I have in concern to the architecture.  At that
point then we can better understand what needs to happen next.  My guess
is between 3-4 hour, possibly sooner before I respond back with my comments.

Cheers!

<M:D/>

>
> Bruce
>



Reply | Threaded
Open this post in threaded view
|

Re: here's what I'm thinking (exploiting variables)

Bruce D'Arcus
In reply to this post by Bruce D'Arcus
On Nov 24, 2004, at 12:57 PM, Bruce D'Arcus wrote:

> This would involve simplifying the driver structure I have now, and
> probably moving the current class-parameter-conditioned mods:mods
> templates into variables.

Minor correction: I mean the mods:modsCollection templates; those that
begin with stuff like:

<xsl:template match="mods:modsCollection[$citation-class='author-year'
or $citation-class='note-bib']"
        mode="enhanced-bib">

So there I'm using a template in another mode/pass, which is
conditioned on the citation-class parameter.  In this approach, either
the variables would have a similar conditional statement (if that's
even possible), or there just be a (rather long and hairy) choose
statement.

Bruce