1

I was previously using XSLT 2.0 for this but decided to make it XSLT 1.0 compatible for certain reasons and from what I've read/found out, variables don't work in XPATH expressions in XSLT 1.0.

This was the original XSL that I used in XSLT 2.0:

<xsl:template match="footnote_ref">
  <xsl:variable as="xs:integer" name="ref" select="."/>
  <xsl:variable name="fid" select="generate-id(../following-sibling::footnote_list[1]/footnote[$ref])"/>
  <sup><a href="#{$fid}">
    <xsl:value-of select="."/>
  </a></sup>
</xsl:template>

For citation n it will link to the nth footnote in the next footnote section.

In XSLT 1.0 this doesn't work, it seems to ignore the [$ref] part and just link to the first footnote regardless. I thought that dyn:evaluate from EXSLT would work so I tried:

<xsl:variable name="fid" select="dyn:evaluate('generate-id(../following-sibling::footnote_list[1]/footnote[$ref])')"/>

If I understand correctly, this should evaluate to generate-id(../following-sibling::footnote_list[1]/footnote[$ref]) but with $ref substituted. In the example they show using variables just fine but this still doesn't work and behaves just like without the dyn:evaluate, ignoring the variable entirely.

Am I doing something wrong or misunderstanding dyn:evaluate? If it matters I'm using libxslt through lxml (Python).

1 Answer 1

1

In XSLT 1.0 this doesn't work, it seems to ignore the [$ref] part and just link to the first footnote regardless.

XSLT 1.0 doesn't support the as attribute on xsl:variable. So in the following:

<xsl:template match="footnote_ref">
  <xsl:variable name="ref" select="."/>
  <xsl:variable name="fid" select="generate-id(../following-sibling::footnote_list[1]/footnote[$ref])"/>
  <sup><a href="#{$fid}">
    <xsl:value-of select="."/>
  </a></sup>
</xsl:template>

$ref is a node set and thus the final predicate in footnote[$ref] says "choose all footnote elements such that the node set $ref is not empty" (i.e. all of them). And when you pass a set of nodes to generate-id you get back the ID of the first node in the set in document order. But if you say

  <xsl:variable name="ref" select="number(.)"/>

then $ref is a number, and the predicate will do the position() based test you require and you should get the correct footnote.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.