Altova Mailing List Archives

Re: [xsl] Question about keys and cross-referencing (was predicate)

From: Chris Loschen <loschen@------------->
Date: 5/5/2003 11:34:00 AM
This discussion of keys and predicates raises an issue I had been 
pondering. I've working on some documents

where the cross-references are entered but without the target specified. 
I've got ids on each of the main entries

(which will be the targets), but I need to look them up in order to find 
the right things.

So I've got an input structure like this:

<e eid="e0001"><hg><hw>keyword</hw></hg><se1>...</se1></e>


<e eid="e1234"><hg><hw>different_keyword</hw></hg><se1>... <xg>See also 

where the <xr> element "keyword" needs to link to the <e> element where the 
<hw> is "keyword".

I'm thinking that I can set up a key like

<xsl:key name="headwords" match="hw" use="ancestor::e/@eid" />

and then reference it in my xr template like

<xsl:attribute name="href"><xsl:text>#</xsl:text><xsl:apply-templates 
select="key('headwords',ancestor::e/@eid)" /></xsl:attribute>

Does that sound right?

Now, an additional twist:

Sometimes I've got several headwords that are identical except for the 
homograph numbers, like so:

<e eid="e0003"><hg><hw>keyword</hw><hom>1</hom></hg><se1>...</se1></e>
<e eid="e0004"><hg><hw>keyword</hw><hom>2</hom></hg><se1>...</se1></e>
<e eid="e0005"><hg><hw>keyword</hw><hom>3</hom></hg><se1>...</se1></e>

and these are referenced like so:

<e eid="e2345"><hg><hw>different_keyword</hw></hg>... <xg>See also 

Is there a way to include those homograph numbers in the key and in the 
cross-reference so that I get the

correct (I hope unique) link?

Thanks again for all of your help!

At 12:35 PM 5/5/03, you wrote:

You want the current() function, which returns the current node (typically 
the node that has matched the template) irrespective of what the context 
node happens to be (e.g. inside a predicate, where the context node has 


select="//rdf:description[@about=current()/@xlink:href]" />

But you'd get better performance using a key:

<xsl:key name="descs-by-about" match="rdf:description" use="@about"/>


<xsl:apply-templates select="key('descs-by-about',@xlink:href)"/>




Texterity ~ XML and PDF ePublishing Services


Chris Loschen, XML Developer

Texterity, Inc.

144 Turnpike Road

Southborough, MA 01772 USA

tel: +1.508.804.3033

fax: +1.508.804.3110

email: loschen@xxxxxxxxxxxxx 

XSL-List info and archive:


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.