xsl-list
[Top] [All Lists]

Re: xsl:number and conditional

2005-05-31 12:41:41
Bruce,

Did you try Michael's latest suggestion of

count="db:footnote|db:citation[not(ancestor::db:footnote)]"

?

My current reading (though I confess your problem is complex enough that I'm not absolutely confident after a cursory glance) is that this should work. I might have suggested the other expression in an effort to account for the fact that XSLT 2.0 functions do not "carry their context" the way named templates do ... but that would be mistaken in this case, as the 'count' attribute takes a pattern to be matched, not an arbitrary XPath expression (as a 'select' attribute does).

The expression above should provide for consecutive numbering of all footnotes with all citations not themselves in footnotes, which is what you want, isn't it? (Not either all footnotes only, or footnotes mixed with citations, depending on whether the context node -- footnote or citation -- itself has a footnote ancestor.)

Cheers,
Wendell

At 12:03 PM 5/31/2005, you wrote:
On 5/31/05, Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:
> > If I understand right, this, in the context of a function:
> >
> > <xsl:number level="any" select="$footcite"
> >
> > count="db:footnote|db:citation[not($footcite/ancestor::db:foot
> > note)]"/>
> >
> > ... should not be counting db:citation elements which are descendents
> > of db:footnote.
> >
> > Is that right?
>
> Not quite. There are two cases:
>
> if $footcite has an ancestor that is a db:footnote, then it counts all
> db:footnote elements

.. but not the db:citation descendent?

> otherwise, it counds all db:footnote and db:citation elements

$footcite in this context is a function parameter that is defined as
element(), but in practice is either db:footnote or db:citation.  So I
have:

  <xsl:function name="bib:number-footcite" as="xs:string">
    <xsl:param name="footcite" as="element()"/>
    <xsl:choose>
      <xsl:when test="$chapters/db:chapter">
        <xsl:number level="any" select="$footcite"

count="db:footnote|db:citation[not($footcite/ancestor::db:footnote)]"
from="db:chapter"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:number level="any" select="$footcite"

count="db:footnote|db:citation[not($footcite/ancestor::db:footnote)]"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:function>

I then call the function in those templates like so:

        <xsl:template match="db:citation">
          <xsl:choose>
<xsl:when test="$citeclass='note-bib' or $citeclass='note-nobib'">
              <xsl:variable name="footnote-number">
                <xsl:value-of select="bib:number-footcite(.)"/>
              </xsl:variable>
              <xsl:text>[</xsl:text>
              <a href="#fn{$footnote-number}" name="fnm{$footnote-number}"
class="footnote-mark">
                <xsl:value-of select="$footnote-number"/>
              </a>
              <xsl:text>]</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:call-template name="bib:format-citation">
                <xsl:with-param name="output-format" select="'xhtml'"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:template>

So if I don't specify not to count db:citation elements that are
descendents of db:footnote, they get double-counted.


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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