xsl-list
[Top] [All Lists]

[xsl] keys and generating footnotes

2007-06-28 21:16:30
I have the following scenario and am having a lot of trouble getting it
to work. I've tried the usual places for a solution but with no luck.
I've tried switching the "match" and "use" attributes in the key to no
avail.

Here is my xml:

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="sample.xsl"?>

<publication>
  <table print="suppress">
    <tr>
      <td>table 1: row 1: column 1<fn idref="1">Works...Nothing is
generated</fn></td>
      <td>table 1: row 1: column 2<fn idref="1">Works...Nothing is
generated</fn></td>
      <td>table 1: row 1: column 3<fn idref="4">Works...Nothing is
generated</fn></td>
    </tr>
  </table>
  <table>
    <tr>
      <td>table 2: row 1: column 1<fn idref="1">Works...Should be
numbered 1 and generate a reference below output table 1 numbered 1 with
this text</fn></td>
      <td>table 2: row 1: column 2<fn idref="2">Works...Should be
numbered 2 and generate a reference below output table 1 numbered 2 with
this text</fn></td>
      <td>table 2: row 1: column 3<fn idref="1">Works...Should be
numbered 1 but not generate any text under output table 1</fn></td>
    </tr>
  </table>
  <table>
    <tr>
      <td>table 3: row 1: column 1<fn idref="1">Doesn't work...Should be
numbered 1 and generate a reference below output table 2 numbered 1 with
this other text</fn></td>
      <td>table 3: row 1: column 2</td>
      <td>table 3: row 1: column 3</td>
    </tr>
  </table>
</publication>

Here is my xsl:

<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


<xsl:output
    method="html"
    indent="yes"
    encoding="iso-8859-1"
    version="4.0"/>

<xsl:key name="fnref" match="table[not(@print)]/tr/td/fn" use="@idref"/>

<xsl:template match="publication">
  <xsl:for-each select="table[not(@print)]">
    <table border="1">
      <xsl:for-each select="tr">
        <tr>
          <xsl:for-each select="td">
            <td>
              <xsl:value-of select="text()"/>
              <xsl:apply-templates mode="idref"
select="ancestor::tr/td/fn[(_at_)idref=current()/fn/@idref][generate-id()=gen
erate-id(key('fnref',@idref)[1])]"/>
            </td>
          </xsl:for-each>
        </tr>
      </xsl:for-each>
      <xsl:apply-templates mode="id"
select="tr/td/fn[generate-id()=generate-id(key('fnref',@idref)[1])]"/>
    </table>
  </xsl:for-each>
</xsl:template>

<xsl:template match="table[not(@print)]/tr/td/fn" mode="idref">
  <sup>
    <xsl:number
count="fn[generate-id()=generate-id(key('fnref',@idref)[1])]" format="1"
from="table" level="any"/>
  </sup>
</xsl:template>

<xsl:template match="fn" mode="id">
  <tr>
    <td colspan="3">
      <xsl:number
count="fn[generate-id()=generate-id(key('fnref',@idref)[1])]" format="1.
" from="table" level="any"/>
      <xsl:value-of select="."/>
    </td>
  </tr>
</xsl:template>
</xsl:stylesheet>

And here is the output I want:

<table border="1">
   <tr>
      <td>table 2: row 1: column 1<sup>1</sup></td>
      <td>table 2: row 1: column 2<sup>2</sup></td>
      <td>table 2: row 1: column 3<sup>1</sup></td>
   </tr>
   <tr>
      <td colspan="3">1. Works...Should be numbered 1 and generate a
reference below output table 1 numbered 1 with this text</td>
   </tr>
   <tr>
      <td colspan="3">2. Works...Should be numbered 2 and generate a
reference below output table 1 numbered 2 with this text</td>
   </tr>
</table>
<table border="1">
   <tr>
      <td>table 3: row 1: column 1</td>
      <td>table 3: row 1: column 2</td>
      <td>table 3: row 1: column 3</td>
   </tr> 
<!-- the tr below and its content is not generated, but I want it to be:
   <tr>
      <td colspan="3">1. Doesn't work...Should be numbered 1 and
generate a reference below output table 2 numbered 1 with this other
text</td>
   </tr>
-->
</table>

How do I set up the key so it "refreshes" on every table element?

Thanks in advance for any forthcoming help.

Dan Whitney

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