Create xsl key by "joining" elements

xslt, xslt-1.0

Solution

Use:

 <xsl:key name="kRendByUsageGi" match="rendition"
  use="../tagUsage[@render=current()/@xml:id]/@gi"/>

Here is a complete verification:

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

When this transformation is applied on the provided XML document:

<t>
  <rendition xml:id="b">color: blue</rendition>
  <rendition xml:id="r">color: red</rendition>

  <tagUsage gi="p" render="b" />
  <tagUsage gi="emph" render="r" />
</t>

the wanted, correct result is produced:

color: blue
========
  color: red

Problem

``` <t> <rendition xml:id="b">color: blue</rendition> <rendition xml:id="r">color: red</rendition> <tagUsage gi="p" render="b" /> <tagUsage gi="emph" render="r" /> </t> ``` How would I create an XSL 1.0 key into rendition elements based on @gi in the tagUsage element, joining rendition/@xml:id to tagUsage/@render? Something like ``` <xsl:key name="rendition-by-tagName" match="rendition" use="//tagUsage[@xml:id of rendition = @render of tagUsage]/@gi" /> ``` so that given "p", the key would return the blue `rendition`; given "emph", the key would return the red `rendition`.

Original source