xsl-list
[Top] [All Lists]

Re: configuring a conditional

2005-05-24 08:44:53

Hi Wendell,

On May 24, 2005, at 10:55 AM, Wendell Piez wrote:

The question I'd ask is what's @linkend. This of course depends on what the context node is -- so we need to consider where this appears.

Source is:

        <db:citation><db:biblioref lnkend="doe99"/></db:citation>

XSLT 2.0 functions work different from templates in that they don't have a context node (or position or size) ... instead of relying on being able to traverse from the context node to its @linkend attribute, for example, you have to pass the node in and then traverse to $node/@linkend.

Could this be an issue here? We need to see more code. But guessing out of the blue (that is, guessing you are defining a function here) I suppose you might try test="$cite-ref is key('refs',$cite-ref/@linkend)[1]".

I'd like to have a function, but thought I'd start with a variable first. I didn't post the code because it's a little hairy, but here goes:

Step 1: template called from db:citation template

  <xsl:template name="bib:format-citation">
    <xsl:param name="output-format" as="xs:string"/>
    <!-- create a temporary tree to hold the processing citations -->
    <xsl:variable name="intermediate-citation">
      <xsl:value-of select="$style-citation/cs:prefix"/>
      <xsl:choose>
        <!-- FIX: add additional sort modes -->
        <xsl:when test="$sort_order-bib='author-year'">
<xsl:apply-templates select="." mode="sort_citation_author-year"> <xsl:with-param name="output-format" select="$output-format" as="xs:string" tunnel="yes"
            />
          </xsl:apply-templates>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="db:biblioref" mode="otherwise"/>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:value-of select="$style-citation/cs:suffix"/>
    </xsl:variable>
    <!--
create formatted output by running appropriate output mode on the temporary
    tree in the intermediate-citation variable
    -->
    <xsl:choose>
      <xsl:when test="$output-format='latex'">
<xsl:apply-templates select="$intermediate-citation" mode="output-latex"/>
      </xsl:when>
      <xsl:when test="$output-format='xhtml'">
<xsl:apply-templates select="$intermediate-citation" mode="output-xhtml"/>
      </xsl:when>
    </xsl:choose>
  </xsl:template>

Step 2: sort

  <xsl:template match="db:citation" mode="sort_citation_author-year">
    <!-- store citation for future use -->
    <xsl:variable name="citation" select="."/>
<xsl:variable name="local-cite-style" select="db:biblioref/@xrefstyle"/>
    <xsl:variable name="idref"
      select="db:biblioref/@linkend, course:reading/@refid"/>
    <xsl:variable name="bibref"
select="$enhanced-biblist/mods:modsCollection/mods:mods[(_at_)ID=$idref]"/>
    <bib:span class="citation">
      <xsl:for-each-group select="$bibref" group-by="@bib:sort-on">
        <xsl:sort select="current-grouping-key()"/>
        <xsl:variable name="refs-for-author-sorted-by-year"
          as="element(mods:mods)*">
          <xsl:perform-sort select="current-group()">
            <xsl:sort select="bib:year"/>
          </xsl:perform-sort>
        </xsl:variable>
<xsl:variable name="first-ref-for-author" as="element(mods:mods)"
          select="$refs-for-author-sorted-by-year[1]"/>
        <xsl:variable name="last-ref-for-author" as="element(mods:mods)"
select="$refs-for-author-sorted-by-year[position() = last()]"/>
        <xsl:for-each-group select="$refs-for-author-sorted-by-year"
          group-adjacent="bib:year">
          <xsl:for-each select="current-group()">
            <xsl:variable name="first-in-author-group"
              select=". is $first-ref-for-author" as="xs:boolean"/>
            <xsl:variable name="last-in-author-group"
              select=". is $last-ref-for-author" as="xs:boolean"/>
            <xsl:variable name="id" select="@ID"/>
<!-- earlier the cite-ref variable was defined as just element(), but for some reason this yielded an empty-sequence error in one case -->
            <xsl:variable name="cite-ref" as="element()*">
<xsl:sequence select="$citation/db:biblioref[(_at_)linkend=$id]"/>
            </xsl:variable>
            <xsl:choose>
<xsl:when test="$citeclass='note-bib' or $citeclass='note-nobib'">
                <xsl:apply-templates select="." mode="citation_note">
                  <xsl:with-param name="first-in-author-group"
                    select="$first-in-author-group"/>
                  <xsl:with-param name="last-in-author-group"
                    select="$last-in-author-group"/>
<xsl:with-param name="local-cite-style" select="$local-cite-style"/> <xsl:with-param name="cite-ref" select="$cite-ref" as="element()*"/>
                </xsl:apply-templates>
              </xsl:when>
              <xsl:otherwise>
<xsl:apply-templates select="." mode="citation_author-year">
                  <xsl:with-param name="first-in-author-group"
                    select="$first-in-author-group"/>
                  <xsl:with-param name="last-in-author-group"
                    select="$last-in-author-group"/>
<xsl:with-param name="local-cite-style" select="$local-cite-style"/> <xsl:with-param name="cite-ref" select="$cite-ref" as="element()*"/>
                </xsl:apply-templates>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:for-each>
        </xsl:for-each-group>
        <xsl:if test="position() != last()">; </xsl:if>
      </xsl:for-each-group>
    </bib:span>
  </xsl:template>

Step 3:

  <xsl:template match="mods:mods" mode="citation_author-year">
    <xsl:param name="local-cite-style"/>
    <xsl:param name="cite-ref" as="element()*"/>
    <xsl:param name="citation"/>
    <xsl:param name="first-in-author-group" as="xs:boolean"/>
    <xsl:param name="last-in-author-group" as="xs:boolean"/>
    <xsl:message>
      <xsl:if test="$cite-ref is key('refs',@linkend)[1]">FIRST</xsl:if>
    </xsl:message>
    <bib:a class="citation" href="#{(_at_)ID}">
<xsl:if test="$first-in-author-group and not($local-cite-style='year')">
        <xsl:choose>
          <xsl:when test="bib:noname-substitute">
            <xsl:value-of select="bib:noname-substitute"/>
          </xsl:when>
          <xsl:otherwise>
<xsl:apply-templates select="mods:name[mods:role/mods:roleTerm=$primary-contributors]"
              mode="short"/>
          </xsl:otherwise>
        </xsl:choose>
<xsl:value-of select="$style-citation/cs:entry/cs:creator/cs:suffix"/>
      </xsl:if>
      <xsl:value-of select="bib:year"/>
      <xsl:value-of select="bib:year-suffix"/>
      <xsl:if test="$cite-ref/@begin">
<xsl:value-of select="$style-citation/cs:entry/cs:point/cs:prefix"/>
        <xsl:value-of select="$cite-ref/@begin"/>
        <xsl:if test="$cite-ref/@end">
          <xsl:text>–</xsl:text>
<xsl:value-of select="bib:number-condense($cite-ref/@begin, $cite-ref/@end)"/>
        </xsl:if>
      </xsl:if>
    </bib:a>
    <xsl:if test="not($last-in-author-group)">, </xsl:if>
  </xsl:template>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



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