1

Following on from my earlier question, the p elements I want to apply the answer to are actually in a result tree fragment.

How do I make the key function:

 <xsl:key name="kRByLevelAndParent" match="p"
  use="generate-id(preceding-sibling::p
                            [not(@ilvl >= current()/@ilvl)][1])"/>

match against p elements in a result tree fragment?

In that answer the key is used via apply-templates:

 <xsl:template match="/*">
  <list>
    <item>
      <xsl:apply-templates select="key('kRByLevelAndParent', '')[1]" mode="start">
        <xsl:with-param name="pParentLevel" select="$pStartLevel"/>
        <xsl:with-param name="pSiblings" select="key('kRByLevelAndParent', '')"/>
      </xsl:apply-templates>
    </item>
  </list>
 </xsl:template>

I'd like to pass my result tree fragment as a parameter, and have the key match p elements in that.

Is this the right way to think about it?

Community
  • 1
  • 1
JasonPlutext
  • 15,352
  • 4
  • 44
  • 84

1 Answers1

3

There are no result tree fragments in XSLT 2.0 and later, you simply have temporary trees. As for keys, they apply to each document and the key function simply has a third argument to pass in the root node or subtree to search so assuming you have your temporary tree $var you can use key('keyname', key-value-expression, $var) to find elements in $var.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110