alternate grouping approach

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

alternate grouping approach

Bruce D'Arcus
OK, I tried to use David's template-based grouping approach, but it's
not working.  The position stuff is STILL screwed up, and I'm about to
scream!

   <xsl:template match="mods:modsCollection" mode="sort_author-year">
    <bib:bibList>
     <xsl:variable name="bibrefs" select="mods:mods"/>
       <xsl:for-each-group select="$bibrefs"
group-by="bib:grouping-key(.)">
         <xsl:sort select="current-grouping-key()" />
           <bib:authorGroup>
             <xsl:apply-templates select="current-group()"
mode="sort_year">
               <xsl:sort select="current-grouping-key()" />
               <xsl:sort select="bib:year(.)" />
               <xsl:with-param name="author-position"
select="position()"/>
             </xsl:apply-templates>
           </bib:authorGroup>
       </xsl:for-each-group>
    </bib:bibList>
   </xsl:template>

   <xsl:template match="mods:mods" mode="sort_year">
     <xsl:param name="author-position"/>
     <result>
       <author-position>
         <xsl:value-of select="$author-position"/>
       </author-position>
       <title>
         <xsl:value-of select="mods:titleInfo/mods:title"/>
       </title>
     </result>
   </xsl:template>

Alas, it doesn't return the correct results:

<?xml version="1.0" encoding="UTF-8"?>
<bib:bibList xmlns:bib="http://purl.org/NET/xbiblio/citeproc">
    <bib:authorGroup>
       <result>
          <author-position>1</author-position>
          <title>Tremblay v. Québec (Attorney General)</title>
       </result>
    </bib:authorGroup>
    <bib:authorGroup>
       <result>
          <author-position>2</author-position>
          <title>Perspectives</title>
       </result>
       <result>
          <author-position>2</author-position>
          <title>The Grandmas Pay a Visit</title>
       </result>
    </bib:authorGroup>
    <bib:authorGroup>
       <result>
          <author-position>3</author-position>
          <title>For a New Regional Geography 1</title>
       </result>
    </bib:authorGroup>
    <bib:authorGroup>
       <result>
          <author-position>4</author-position>
          <title>Review of Moral Economy and Popular Protest</title>
       </result>
       <result>
          <author-position>4</author-position>
          <title>Stories, Identities, and Political Change</title>
       </result>
    </bib:authorGroup>
    <bib:authorGroup>
       <result>
          <author-position>5</author-position>
          <title>Senators Stamp OK on Anti-Terrorism Laws</title>
       </result>
    </bib:authorGroup>
    <bib:authorGroup>
       <result>
          <author-position>6</author-position>
          <title>Riots and Rituals</title>
       </result>
    </bib:authorGroup>
</bib:bibList>

BTW, one of the reasons I wanted to try this approach is that it then
makes it easy to solve the grouping-by-reference-type issue.  So I'm
imaging a temporary tree that looks like:

<bib:bibList>
    <bib:uncitedGroup>
      <bib:authorGroup>
        <bib:item>
           ...
        </bib:item>
      </bib:authorGroup>
    </bib:uncitedGroup>
    <bib:mainGroup>
      <bib:authorGroup>
        <bib:item>
           ...
        </bib:item>
      </bib:authorGroup>
    </bib:mainGroup>
<bib:bibList>

I''m thinking it might be more efficient to transform mods into a
temporary tree representation that is a perfect mirror of the CSL
language. Does that seem right?

Yo David, where are you??? I gotta go out for a few hours, but I want
to get this working today!

Bruce



Reply | Threaded
Open this post in threaded view
|

Re: alternate grouping approach

Bruce D'Arcus
Actually, I think the best median approach is to keep my earlier use of
a global variable to hold the enhanced biblist, but to split sorting
into different modes in separate templates.

Testing on my sample doc shows this is quite fast, and it's a lot
easier to manage than the existing code.  And it's clear the problem
with the damned author position() thing is not a problem of this
approach; it's just a PITA.  I can't figure it out!  I can only hope
someone on the xsl list does!

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
   xmlns:xdoc="http://www.pnp-software.com/XSLTdoc"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:mods="http://www.loc.gov/mods/v3"
   xmlns:cs="http://purl.org/NET/xbiblio/csl"
   xmlns:bib="http://purl.org/NET/xbiblio/citeproc"
   exclude-result-prefixes="xdoc mods xs cs bib">

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

   <xsl:param name="sort_order" select="'author-year'"/>

   <xsl:template match="/">
     <result>
       <xsl:copy-of select="$enhanced-biblist"/>
     </result>
   </xsl:template>

    <xsl:variable name="enhanced-biblist">
      <xsl:choose>
        <xsl:when test="$sort_order='citekey'">
          <xsl:apply-templates select="list" mode="sort_citekey"/>
        </xsl:when>
        <xsl:when test="$sort_order='cited'">
          <xsl:apply-templates select="list" mode="sort_cited"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="list" mode="sort_author-year"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:template match="list" mode="sort_author-year">
      <xsl:for-each-group select="item" group-by="@author">
        <xsl:sort select="current-grouping-key()"/>
        <xsl:variable name="author-position" select="position()"/>
        <xsl:for-each-group select="current-group()" group-by="@year">
          <xsl:sort select="current-grouping-key()" />
          <xsl:for-each select="current-group()">
            <xsl:variable name="shorten-author" as="xs:boolean"
                select="$author-position > 1" />
      <xsl:variable name="year">
            <xsl:value-of select="current-grouping-key()"/>
              <xsl:if test="last() > 1">
                <xsl:number value="position()" format="a"/>
              </xsl:if>
            </xsl:variable>
            <xsl:apply-templates select=".">
              <xsl:with-param name="year" select="$year"/>
              <xsl:with-param name="shorten-author"
select="$shorten-author"/>
            </xsl:apply-templates>
          </xsl:for-each>
        </xsl:for-each-group>
      </xsl:for-each-group>
    </xsl:template>

    <xsl:template match="item">
      <xsl:param name="shorten-author"/>
      <xsl:param name="year"/>
      <item>
        <shorten-author>
          <xsl:value-of select="$shorten-author"/>
        </shorten-author>
        <year>
          <xsl:value-of select="$year"/>
        </year>
      </item>
     </xsl:template>

</xsl:stylesheet>



Reply | Threaded
Open this post in threaded view
|

Re: alternate grouping approach

M. David Peterson-2
In reply to this post by Bruce D'Arcus
Bruce,

A lot is on schedule for the weekend, the next in the list the
clean-up of the code base issues using a grouping approach that will
work.  The approach a sampled to xsl-list yesterday will work just
fine.  It just needs to be continued to enable the grouping and
subsequent output you are looking for.

I will be starting this in about two hours (my "day" just began about
1/2 hour ago).

On 4/23/05, Bruce D'Arcus <[hidden email]> wrote:

> OK, I tried to use David's template-based grouping approach, but it's
> not working.  The position stuff is STILL screwed up, and I'm about to
> scream!
>
>   <xsl:template match="mods:modsCollection" mode="sort_author-year">
>    <bib:bibList>
>     <xsl:variable name="bibrefs" select="mods:mods"/>
>       <xsl:for-each-group select="$bibrefs"
> group-by="bib:grouping-key(.)">
>         <xsl:sort select="current-grouping-key()" />
>           <bib:authorGroup>
>             <xsl:apply-templates select="current-group()"
> mode="sort_year">
>               <xsl:sort select="current-grouping-key()" />
>               <xsl:sort select="bib:year(.)" />
>               <xsl:with-param name="author-position"
> select="position()"/>
>             </xsl:apply-templates>
>           </bib:authorGroup>
>       </xsl:for-each-group>
>    </bib:bibList>
>   </xsl:template>
>
>   <xsl:template match="mods:mods" mode="sort_year">
>     <xsl:param name="author-position"/>
>     <result>
>       <author-position>
>         <xsl:value-of select="$author-position"/>
>       </author-position>
>       <title>
>         <xsl:value-of select="mods:titleInfo/mods:title"/>
>       </title>
>     </result>
>   </xsl:template>
>
> Alas, it doesn't return the correct results:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <bib:bibList xmlns:bib="http://purl.org/NET/xbiblio/citeproc">
>    <bib:authorGroup>
>       <result>
>          <author-position>1</author-position>
>          <title>Tremblay v. Québec (Attorney General)</title>
>       </result>
>    </bib:authorGroup>
>    <bib:authorGroup>
>       <result>
>          <author-position>2</author-position>
>          <title>Perspectives</title>
>       </result>
>       <result>
>          <author-position>2</author-position>
>          <title>The Grandmas Pay a Visit</title>
>       </result>
>    </bib:authorGroup>
>    <bib:authorGroup>
>       <result>
>          <author-position>3</author-position>
>          <title>For a New Regional Geography 1</title>
>       </result>
>    </bib:authorGroup>
>    <bib:authorGroup>
>       <result>
>          <author-position>4</author-position>
>          <title>Review of Moral Economy and Popular Protest</title>
>       </result>
>       <result>
>          <author-position>4</author-position>
>          <title>Stories, Identities, and Political Change</title>
>       </result>
>    </bib:authorGroup>
>    <bib:authorGroup>
>       <result>
>          <author-position>5</author-position>
>          <title>Senators Stamp OK on Anti-Terrorism Laws</title>
>       </result>
>    </bib:authorGroup>
>    <bib:authorGroup>
>       <result>
>          <author-position>6</author-position>
>          <title>Riots and Rituals</title>
>       </result>
>    </bib:authorGroup>
> </bib:bibList>
>
> BTW, one of the reasons I wanted to try this approach is that it then
> makes it easy to solve the grouping-by-reference-type issue.  So I'm
> imaging a temporary tree that looks like:
>
> <bib:bibList>
>    <bib:uncitedGroup>
>      <bib:authorGroup>
>        <bib:item>
>           ...
>        </bib:item>
>      </bib:authorGroup>
>    </bib:uncitedGroup>
>    <bib:mainGroup>
>      <bib:authorGroup>
>        <bib:item>
>           ...
>        </bib:item>
>      </bib:authorGroup>
>    </bib:mainGroup>
> <bib:bibList>
>
> I''m thinking it might be more efficient to transform mods into a
> temporary tree representation that is a perfect mirror of the CSL
> language. Does that seem right?
>
> Yo David, where are you??? I gotta go out for a few hours, but I want
> to get this working today!
>
> Bruce
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> <a href="http://ads.osdn.com/?ad_ide95&alloc_id396&opclick">http://ads.osdn.com/?ad_ide95&alloc_id396&opclick
> _______________________________________________
> xbiblio-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/xbiblio-devel
>


--
<M:D/>

:: M. David Peterson ::
XML & XML Transformations, C#, .NET, and Functional Languages Specialist


Reply | Threaded
Open this post in threaded view
|

Re: alternate grouping approach

Bruce D'Arcus
On Apr 23, 2005, at 7:41 PM, M. David Peterson wrote:

> The approach a sampled to xsl-list yesterday will work just fine. It
> just needs to be continued to enable the grouping and subsequent
> output you are looking for.

It seems I was just posting as you were.  The problem is it's really
difficult for me to evaluate.  If you can create the expected output I
posted in the followup to Mike, that's great.

I'm thinking that the example I just posted -- which combines modes, a
global variable temporary tree, and apply-templates -- will be the
easiest to handle.  One of the things I found when dealing with
multiple trees (as in citeproc) is it's often really difficult to
localize what's going on.  That why I like having an enhanced-biblist
global variable.  You'll note that it's a lot cleaner than the existing
code, even if it still doesn't work!

The grouping problem (still not solved by anyone, I might add) is not
specific to either approach.

Bruce