Re: [xsl] "grouping" footnote numbers

Subject: Re: [xsl] "grouping" footnote numbers
From: Brandon Ibach <brandon.ibach@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 11 Oct 2011 09:07:43 -0400
By calling key() from the context of the xref, you're only getting
back the xrefs with the same @href, so you'll only ever have one group
and position() will only ever return 1.

It may not be terribly efficient, but you could add this to the
<xsl:number> in the XSLT code you posted:

count="xref[not(@href = preceding::xref/@href)]"

Or, replace the <xsl:number> completely with:

<xsl:value-of select="count(distinct-values(preceding::xref/@href)) + 1"/>

Determining which one works better is left as an exercise for the OP. :)

-Brandon :)


On Tue, Oct 11, 2011 at 8:42 AM, Emma Burrows <Emma.Burrows@xxxxxxxxxxx>
wrote:
> From: David Carlisle [mailto:davidc@xxxxxxxxx]
>> change that to xsl:value-of select="position()"  having grouped them all
>> you just want to know which group you ar in and position(0 tells you that
>
> Thank you very much for looking into this. Alas, this XSL:
>
> <xsl:key name="fn" match="xref" use="@href"/>
> ...
> <sup>
>  <xsl:for-each-group select="key('fn', @href)" group-by="@href">
>    <xsl:value-of select="position()"/>
>  </xsl:for-each-group>
> </sup>
>
> Just results in every reference being numbered as 1. I'm not sure why -
either because the grouping is based on a key or because this appears in the
"xref" template?
>
> To move this forward, here is some actual XML for you:
>
> Input
> =====
>    <p><b>Caesarean section</b></p>
>    <p>Single dose<xref href="footnote-113022.dita#bnf_113022" type="fn"/> of
i/v cefuroxime</p>
>    <p>Administer immediately after umbilical cord is clamped. Add i/v
teicoplanin<xref href="footnote-202621.dita#bnf_202621" type="fn"/></p>
>    <p><b>Hysterectomy</b><xref href="footnote-204127.dita#bnf_204127"
type="fn"/></p>
>    <p>Single dose<xref href="footnote-113022.dita#bnf_113022" type="fn"/> of
i/v cefuroxime + i/v
>        metronidazole<xref href="footnote-113019.dita#bnf_113019"
type="fn"/>
>      <i>or</i> i/v gentamicin + i/v metronidazole<xref
href="footnote-113019.dita#bnf_113019" type="fn"/>
>      <i>or</i> i/v co-amoxiclav alone</p>
>    <p>Use single dose<xref href="footnote-113022.dita#bnf_113022"
type="fn"/> of
>        i/v gentamicin + i/v metronidazole<xref
href="footnote-113019.dita#bnf_113019" type="fn"/> or
>        add i/v teicoplanin<xref href="footnote-202621.dita#bnf_202621"
type="fn"/></p>
>    <p><b>Termination of pregnancy</b></p>
>    <p>Single dose<xref href="footnote-113022.dita#bnf_113022" type="fn"/> of
oral metronidazole</p>
>
> XSL:
> ====
>
>  <xsl:key name="fn" match="xref[@type='fn']" use="@href"/>
>
>  <xsl:template match="p">
>    <xsl:element name="{local-name()}"><xsl:apply-templates/></xsl:element>
>  </xsl:template>
>
>  <xsl:template match="xref">
>    <a href="{@href}">
>      <sup>
>        <xsl:for-each-group select="key('fn', @href)" group-by="@href">
>          <xsl:number level="any"/>
>        </xsl:for-each-group>
>      </sup>
>    </a>
>  </xsl:template>
>
> (Incorrect) Output:
> ===================
>
>  <p>Caesarean section</p>
>  <p>Single dose<a href="footnote-113022.dita#bnf_113022"><sup>1</sup></a> of
i/v cefuroxime</p>
>  <p>Administer immediately after umbilical cord is clamped. Add i/v
teicoplanin<a href="footnote-202621.dita#bnf_202621"><sup>2</sup></a></p>
>  <p>Hysterectomy<a
href="footnote-204127.dita#bnf_204127"><sup>3</sup></a></p>
>  <p>Single dose<a href="footnote-113022.dita#bnf_113022"><sup>1</sup></a> of
i/v cefuroxime + i/v
>    metronidazole<a href="footnote-113019.dita#bnf_113019"><sup>5</sup></a>
>    or i/v gentamicin + i/v metronidazole<a
href="footnote-113019.dita#bnf_113019"><sup>5</sup></a>
>    or i/v co-amoxiclav alone</p>
>  <p>Use single dose<a
href="footnote-113022.dita#bnf_113022"><sup>1</sup></a> of
>    i/v gentamicin + i/v metronidazole<a
href="footnote-113019.dita#bnf_113019"><sup>5</sup></a> or
>    add i/v teicoplanin<a
href="footnote-202621.dita#bnf_202621"><sup>2</sup></a></p>
>  <p>Termination of pregnancy</p>
>  <p>Single dose<a href="footnote-113022.dita#bnf_113022"><sup>1</sup></a> of
oral metronidazole</p>
>
> So essentially, I get footnote reference numbers 1, 2, 3 and 5. I'd like
number 5 to come out as number 4 as I'd expect. Thank again, David, and
whoever would like to jump in to give you a break. :)

Current Thread