xsl-list
[Top] [All Lists]

position and grouping?

2004-10-14 10:42:28
I'm a little confused about an interaction I'm getting between grouping and a position test. The below template gets applied from another template that groups and sorts records by author and year. It works fine when there is only one author name within an author group, but doesn't when there are more.

<xsl:template match="mods:name" mode="full">
    ...
<xsl:when test="$sort-order='first-author' and position() = 1 and not(parent::mods:relatedItem)"> <xsl:apply-templates select="mods:namePart[(_at_)type='family'] | mods:namePart[not(@type)]"/>
      <xsl:text>, </xsl:text>
      <xsl:apply-templates select="mods:namePart[(_at_)type='given']"/>
    </xsl:when>
    ...
</xsl:template>

So, for example, I want:

Doe, J. and S. Jones
Doe, J. and S. Jones
Smith, S. and Abe Abel

.... but instead get:

J. Doe. and S. Jones
J. Doe, and S. Jones
Smith, S. and Abe Abel

(Actually, the second in the group should be replaced by three em-dashes, but I can leave that aside for now).

So it seems when I use the "position()" test above, I am not just testing the position of the name within the record, but (also?) the name within a group of records. Can someone clarify this?

Here's the templates it's invoked within:

<xsl:template match="mods:modsCollection[$citation-class='author-year']"
              mode="bibliography">
  <xsl:variable name="first" as="xs:boolean" select="position() = 1" />
  <xsl:variable name="author-name" select="bib:grouping-key(.)"/>
  <xsl:variable name="reftype" select="mods:reftype"/>
<!--
There must be a more elegant way, but below I need to again use
grouping to handle multiple listings by the same author. Chicago specifies
that all single-authored works by the same author after the first one
should replace the author name by three em-dashes and a period. Ideally I'd do this in the grouping and sorting processing in the "processed-bibrefs" mode,
but I can't figure out.

Along with that, I'm not sure how to implement grouping by reference type
(which is supported in the citation style language).

Finally, I need to work out how, or whether, to implement the inheritance
feature in the current citation style language.
-->
  <xsl:for-each-group select="mods:mods" group-by="bib:grouping-key(.)">
    <xsl:for-each select="current-group()">
<xsl:variable name="first" as="xs:boolean" select="position() = 1" />
      <p class="bibref" id="{(_at_)ID}">
        <xsl:value-of select="$bibref-before"/>
        <span class="creator">
          <xsl:choose>
            <xsl:when test="count(current-group()) = 1">
              <xsl:choose>
                <xsl:when test="not($first and position() = 1)">
                  <xsl:text>———.</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <xsl:when test="mods:name">
                      <xsl:apply-templates select="mods:name" mode="full">
                        <xsl:with-param name="sort-order"
                                select="$style-biblio/@author-as-sort-order" />
                      </xsl:apply-templates>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select="mods:noname-substitute"/>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="mods:name">
                  <xsl:apply-templates select="mods:name" mode="full"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="mods:noname-substitute"/>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </span>
        <xsl:choose>
          <xsl:when test="mods:refclass='part-inSerial'">
            <xsl:choose>
              <xsl:when
test="mods:reftype=$style-biblio/cs:reftype[not(@inherit-from)]/@name">
                <xsl:apply-templates
select="$style-biblio/cs:reftype[not(@inherit-from) and @name=$reftype]/
                            (cs:* except cs:creator)">
                  <xsl:with-param name="source" select="."/>
                </xsl:apply-templates>
              </xsl:when>
              <xsl:otherwise>
                <xsl:apply-templates
select="$style-biblio/cs:reftype[not(@inherit-from) and @name='article']/
                            (cs:* except cs:creator)">
                  <xsl:with-param name="source" select="."/>
                </xsl:apply-templates>            
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:when test="mods:refclass='part-inMonograph'">
            <xsl:choose>
<xsl:when test="mods:reftype=$style-biblio/cs:reftype[not(@inherit-from) and @name=$reftype]">
                <xsl:apply-templates
select="$style-biblio/cs:reftype[not(@inherit-from) and @name=$reftype]/
                            (cs:* except cs:creator)">
                  <xsl:with-param name="source" select="."/>
                </xsl:apply-templates>
              </xsl:when>
              <xsl:otherwise>
                <xsl:apply-templates
select="$style-biblio/cs:reftype[not(@inherit-from) and @name='chapter']/
                            (cs:* except cs:creator)">
                  <xsl:with-param name="source" select="."/>
                </xsl:apply-templates>            
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <xsl:choose>
<xsl:when test="mods:reftype=$style-biblio/cs:reftype[not(@inherit-from) and @name=$reftype]">
                <xsl:apply-templates
select="$style-biblio/cs:reftype[not(@inherit-from) and @name=$reftype]/
                            (cs:* except cs:creator)">
                  <xsl:with-param name="source" select="."/>
                </xsl:apply-templates>
              </xsl:when>
              <xsl:otherwise>
                <xsl:apply-templates
select="$style-biblio/cs:reftype[not(@inherit-from) and @name='book']/
                            (cs:* except cs:creator)">
                  <xsl:with-param name="source" select="."/>
                </xsl:apply-templates>            
              </xsl:otherwise>
            </xsl:choose>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:value-of select="$bibref-after"/>
      </p>
    </xsl:for-each>
  </xsl:for-each-group>
</xsl:template>

Bruce


<Prev in Thread] Current Thread [Next in Thread>