[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: NMTOKENS and xsl:key

Subject: RE: NMTOKENS and xsl:key
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 8 Jan 2007 00:52:12 -0000
RE:  NMTOKENS and xsl:key
You don't say whether this is a schema-aware stylesheet. If it is, then the
type xs:NMTOKENS will be recognized, the typed value of @target will be a
sequence of tokens, and 

<xsl:key match="item" use="@target"/>

will index the value of each token.

If it's not schema-aware then you need to split the value "by hand":

<xsl:key match="item" use="tokenize(@target, '\s+')"/> 

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

> -----Original Message-----
> From: Houghton,Andrew [mailto:houghtoa@xxxxxxxx] 
> Sent: 07 January 2007 22:58
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  NMTOKENS and xsl:key
> 
> 
> I'm hoping someone on the list might be able to provide some 
> insight in how I might address the following issue.  I'm 
> using Saxon 8.8 and XSL 2.0 for developing a transform.  The 
> source document looks something like:
> 
> <document>
>   <section>
>     <item target="abc def ghi"/>
>     <item target="foo bar"/>
>     <item target="abc bar"/>
>     <item target="def foo"/>
>   </section>
>   <section>
>     <item target="abc"/>
>     <item target="foo"/>
>     <item target="ghi bar"/>
>   </section>
> </document>
> 
> The <section> and <item> elements are repeatable and the 
> target attribute is an NMTOKEN list.
> 
> Since the source document is quite large, I was hoping to use 
> xsl:key to index each token value in the item's target 
> attribute so I could query for all the items that might 
> contain a particular token value, e.g., "foo".
> 
> However, looking at xsl:key it seems to me that it will only 
> index the entire NMTOKEN list as a single value.  What I'm 
> trying to accomplish when I query for the token value "foo", 
> is that I want xsl:key to return the following node
> list:
> 
>   /document/section[1]/item[2]
>   /document/section[1]/item[4]
>   /document/section[2]/item[2]
> 
> correspondingly if I query for "abc" I want xsl:key to be 
> able to return the following node list:
> 
>   /document/section[1]/item[1]
>   /document/section[1]/item[3]
>   /document/section[2]/item[1]
> 
> does anybody know of anyway I can get xsl:key to index each 
> token in the NMTOKEN list for the target attribute?  I 
> realize I could write an XPath expression, but continually 
> iterating over a large document looking for different token 
> values would be extremely slow which is one of the main 
> reason why I was looking at using xsl:key.
> 
> Can you think of any alternate solutions to the problem.
> 
> BTW, the tokens in the list are *not* known in advance to the 
> transform.
> 
> 
> Thanks, Andy.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.