Subject: Re: current() within a key element's @use
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 28 Dec 2012 09:31:45 -0800
|
On Fri, Dec 28, 2012 at 8:38 AM, Chris Maloney <voldrani@xxxxxxxxx> wrote:
> As for a work-around, the following works with xsltproc, but
> interestingly, not with Saxon. Saxon complains "key() function cannot
> be used here". (This is a variant of the XSLT that Dimitre posted on
> SO):
>
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output omit-xml-declaration="yes" indent="yes"/>
>
> <xsl:key name='kTagUsage' match='tagUsage' use='@render'/>
> <xsl:key name="kRendByUsageGi" match="rendition"
> use="key('kTagUsage', @xml:id)/@gi"/>
>
> <xsl:template match="/">
> <xsl:copy-of select="key('kRendByUsageGi', 'p')/text()"/>
> ========
> <xsl:copy-of select="key('kRendByUsageGi', 'emph')/text()"/>
> </xsl:template>
> </xsl:stylesheet>
>
There is a "slight" difference: I didn't use key() inside the
expression in the "use" attribute (I believe the error is raised to
prevent cirkular key definition) -- and the below transformation is
working with Saxon:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="kRendByUsageGi" match="rendition"
use="../tagUsage[@render=current()/@xml:id]/@gi"/>
<xsl:template match="/">
<xsl:copy-of select="key('kRendByUsageGi', 'p')/text()"/>
========
<xsl:copy-of select="key('kRendByUsageGi', 'emph')/text()"/>
</xsl:template>
</xsl:stylesheet>
Cheers,
Dimitre
|