Subject: Re: [xsl] Referencing unique values by their order number. From: Andreas Kemkes <a5sk4s@xxxxxxxxx> Date: Tue, 12 Dec 2006 12:23:12 -0800 (PST) |
With the invaluable input from David, I was able to solve it without using keys - his comments were useful beyond the direct issue that I'm trying to solve and I will revisit keys. The following did the trick: <xsl:variable name="items" select="item[not(preceding-sibling::item = .)]"/> ... <elements> <xsl:apply-templates mode="elements"> <xsl:with-param name="items" select="$items"/> </xsl:apply-templates> </elements> ... ... <xsl:template match="text" mode="elements"> <xsl:param name="items"/> <xsl:variable name="item" select="preceding-sibling::item[1]"/> <element> <item><xsl:value-of select="count($items[.=$item]/preceding-sibling::item[not(.=preceding-sibling ::item)])"/></item> <text><xsl:value-of select="."/></text> </element> </xsl:template> Thanks for all the help. Andreas ----- Original Message ---- From: David Carlisle <davidc@xxxxxxxxx> To: a5sk4s@xxxxxxxxx Cc: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Sent: Friday, December 8, 2006 5:17:49 PM Subject: Re: [xsl] Referencing unique values by their order number. > The real input example has various sections of the original example - > aside from being also more convoluted in other aspects. All sections > need to use their own unique value set and reference it appropriately. > My concern was that the top-level (i.e., somewhat global) key feature > wouldn't be appropriate. you can make keys work locally by using concat to make up specific identifiers, for example if you want all keys to be unique to descendants of a given chapter, just make the chapter part of the key ie instead of use="." use use="concat(ancestor::chapter/@id,':',.) or whatever works in your case. > Is there a way to do the same without keys? perhaps, perhaps not, apart from making things faster the functional key notation alows you to avoid some problems related to the fact that you can't bind variables in xpath 1, variable binding has to be done at the xslt level so can't happen within a path. some cases of course don't need variables, some do, not sure which case you are in, There are parts of the world where it isn't 1 in the morning, someone else can think about it:-) David _____________________________________________________________________________ _______ Cheap talk? Check out Yahoo! Messenger's low PC-to-Phone call rates. http://voice.yahoo.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Referencing unique values, David Carlisle | Thread | [xsl] How to get cotext of foreach , PiGalKOM |
Re: [xsl] xmlns:local="#local-funct, Florent Georges | Date | RE: [xsl] XSL limitations?, Michael Kay |
Month |