RE: [xsl] IDREFS and key()

Subject: RE: [xsl] IDREFS and key()
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 29 Nov 2005 08:15:38 -0000
In 2.0 you don't need the key() function to do this, you can do it using the
idref() function.

If you want to do it using key(), your key definition would work (the value
would be indexed on each string appearing in the @references attribute)
provided you use a schema-aware processor and @references has a list type.

If you want to do it using a 2.0 basic processor, you can specify
use="tokenize(@references, '\s')".

If you want to do it using 1.0, you're a masochist...

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Dan Vint [mailto:dvint@xxxxxxxxx] 
> Sent: 29 November 2005 02:31
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] IDREFS and key()
> 
> I have an element that contains an IDREFS attribute like the 
> following:
> 
> <Attribute id="aAtt" references="foo bar"><Name>Att</Name></Attribute>
> 
> The references attribute is defined as an IDREFS and the schema and 
> document that this lives in are all valid.
> 
> I want to use the references attribute in a key definition so 
> I can reverse 
> the relationship and in this case from the element identified 
> as foo or 
> bar, indicate that the Attribute element, named Att links to it.
> 
> My key definition is this:
> 
> <xsl:key name="attribute-references" match="Attribute" 
> use="@references"/>
> 
> I process this with a for-each as follows:
> 
> <xsl:for-each select="key('attribute-references', $parentElement)>
> 
> $parentElement is set to the id value that is in the 
> references attribute.
> 
> In this example when there are multiple values in the 
> @references, nothing 
> is found, but if I remove in this case the second value, I 
> produce results. 
> It seems like the key() is trying to match my value of 'foo' 
> against the 
> complete string of 'foo bar', rather than doing a "contains" 
> sort of match. 
> Is this what is expected? When I provide the full 'foo bar' 
> to the for-each 
> I now match this Attribute definition.
> 
> How do I get the key() function to break up the IDREFS and 
> process the 
> individual values? I tried using id() in the key definition 
> but that didn't 
> help.
> 
> ..dan
> --------------------------------------------------------------
> -------------
> Danny Vint
> 
> Specializing in Panoramic Images of California and the West
> http://www.dvint.com
> 
> voice: 510-522-4703
> 
> When H.H. Bennett was asked why he preferred to be out
> shooting landscapes rather than spending time in his portrait studio:
> 
> "It is easier to pose nature and less trouble to please."
> 
> http://www.portalwisconsin.org/bennett_feature.cfm

Current Thread