Re: [xslt] key() in match pattern of xsl:key



On Sun, 11 Dec 2005, Daniel Veillard wrote:

>   Just send the input XSL and input XML as attachments and describe what
> you're testing, that will be sufficient if no code change is needed then
> (i.e. assuming the ouptut from the current version works as you expect).

I've moved the XSL and XML from my previous post to attachments.  I 
believe the description is really one sentence:

Check that the match pattern of an xsl:key may contain a forward reference 
to another xsl:key.

Thanks.

Joel
<?xml version="1.0" encoding="iso-8859-1"?>

<test>
  <A>1.0</A>
  <A>2.0</A>
  <A>3.0</A>
  <B>1.0</B>
  <B>4.0</B>
  <B>5.0</B>
</test>
<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:transform
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>

<xsl:output method="text" />

<xsl:key name="keyA" match="A" use="." />
<xsl:key name="keyAnotB" match="A[ not( key( 'keyB', . ) ) ]" use = "." />
<xsl:key name="keyB" match="B" use="." />
<xsl:variable name="AnotB" select="//A[ not( key( 'keyB', . ) ) ]" />

<xsl:template match="/">
  <xsl:text>A:&#10;</xsl:text>
  <xsl:for-each select="//A">
    <xsl:call-template name="print_membership" />
  </xsl:for-each>
  <xsl:text>B:&#10;</xsl:text>
  <xsl:for-each select="//B">
    <xsl:call-template name="print_membership" />
  </xsl:for-each>
  <xsl:text>AnotB:&#10;</xsl:text>
  <xsl:for-each select="$AnotB">
    <xsl:call-template name="print_membership" />
  </xsl:for-each>
</xsl:template>

<xsl:template name="print_membership">
  <xsl:text>  </xsl:text><xsl:value-of select="." />
  <xsl:text>: A=</xsl:text>
  <xsl:value-of select="count( key( 'keyA', . ) )" />
  <xsl:text>, B=</xsl:text>
  <xsl:value-of select="count( key( 'keyB', . ) )" />
  <xsl:text>, AnotB=</xsl:text>
  <xsl:value-of select="count( key( 'keyAnotB', . ) )" />
  <xsl:text>&#10;</xsl:text>
</xsl:template>

</xsl:transform>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]