xsl-list
[Top] [All Lists]

Re: [xsl] Referencing unique values by their order number.

2006-12-12 13:35:15
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(_at_)nag(_dot_)co(_dot_)uk>
To: a5sk4s(_at_)yahoo(_dot_)com
Cc: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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
 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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--