This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Pattern: Replicating Key Table Construction for Debugging
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: XSL List <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 20 Feb 2002 10:09:01 +0000
- Subject: Re: [xsl] Pattern: Replicating Key Table Construction for Debugging
- Organization: Jeni Tennison Consulting Ltd
- References: <3C730ECC.A19E8DE4@isogen.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
W. Eliot Kimber wrote:
> There's no direct way to see what the entries in a table are (e.g.,
> the equivalent of Hastable.getKeySet() in Java). However, you can
> easily replicate what the key table is doing and sanity check what's
> happening. All you do is a for-each from the root that uses the same
> select rule as the key.
>
> For example, if your key declaration is:
>
> <xsl:key name="primary"
> match="index.marker"
> use="normalize-space(concat(primary/@sortas,
> primary[not(@sortas)]))"/>
>
> Then to see what is actually going into the table, just do this:
>
> <xsl:for-each select="//index.marker">
> <xsl:message>key='<xsl:value-of
> select="normalize-space(concat(primary/@sortas,
> primary[not(@sortas)]))"/>'</xsl:message>
> </xsl:for-each>
Just to add to this... In some cases, the key declaration may actually
be adding several entries to the table for each matched node. For
example:
<xsl:key name="keywords" match="article" use="keywords/keyword" />
If the use attribute evaluates to a node set, then you get one entry
per node in that node set (all pointing to the same matched article).
So this key indexes each article against each of its keywords.
Therefore in these cases, the xsl:for-each you need is:
<xsl:for-each select="//article/keywords/keyword">
<xsl:message>key='<xsl:value-of select="." />'</xsl:message>
</xsl:for-each>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list