[xsl] id attribution in template match

Subject: [xsl] id attribution in template match
From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx>
Date: Tue, 29 Sep 2009 20:56:20 +1300
Since switching from DTD-based to XSD-based documents, a number of templates
which make use of the id() function have stopped working. It's not a
processor problem because it occurs with Xalan, Saxon and libxslt.

This used to work, outputting the content of whatever element in the
document had the given id:
----
  <xsl:template match="jump[@idref]">
    <xsl:value-of select="normalize-space(id(@idref))" />
  </xsl:template>
----

Now it does not, and I have had to replace it with
----
  <xsl:template match="jump[@idref]">
    <xsl:variable name="jid" select="@idref" />
    <xsl:value-of select="normalize-space(//*[@id=$jid])" />
  </xsl:template>
----

The schema correctly identifies all id attributes as type xs:ID, and all
idref attributes as type xs:IDREF.

So that's question 1, is there a hidden trap with id(@idref) type
expressions here?

Question 2 follows from my using the above workaround, because it isn't
obvious how to apply it in template matches.

For example I have a template declared like so:
----
  <xsl:template match="jump[@idref][local-name(id(@idref))='footnote']">
  ..
  </xsl:template>
----

This is no longer matching jumps which point to footnotes, so I tried the
same technique as above:
----
  <xsl:template match="jump[@idref][local-name(//*[@id =
./@idref])='footnote']">
  ..
  </xsl:template>
----

I know this won't work because the . in the last predicate matches the wrong
element. I can't put the idref in a variable and use that because I would
have to do that outside the template. Is there a particular technique that
would allow me to evaluate this test properly (of course a solution to the
first problem might render this irrelevant).

Thanks
Trevor

Current Thread