On 12/20/06, James Cummings <cummings(_dot_)james(_at_)gmail(_dot_)com> wrote:
Hiya, I'm sure I'm just looking at this upside down, but here goes:
I want to do something like this:
<xsl:template name="makeSegLabel">
<xsl:variable name="ana" select="tokenize(@ana, '(\s+)')"/>
<xsl:for-each select="$ana">
<xsl:value-of select="."/><xsl:text>:</xsl:text>
<xsl:value-of select="//category[(_at_)id = .]/catDesc"/>
</xsl:for-each>
</xsl:template>
Where I want to tokenize the ana attribute on the element which called
this template, and then for each whitespace separated value, I want to
put it out, and then go get a description of what that value means
from elsewhere in the document.
However, I'm rightly told that I cannot select a node here because the
context is an atomic value.
I'm sure I'm being stupid and there is a better way to do this.
No, this is the right way - you just need to maintain a pointer the
content node (or root) outside of the tokenize, for example:
<xsl:template name="makeSegLabel">
<xsl:variable name="ana" select="tokenize(@ana, '(\s+)')"/>
<xsl:variable name="this" select="."/>
<xsl:for-each select="$ana">
<xsl:value-of select="$this"/>
Also, you really ought to be using a key instead of:
<xsl:value-of select="//category[(_at_)id = .]/catDesc"/>
eg:
<xsl:key name="cat-by-id" match="category" use="@id"/>
Ultimately it could all be rewritten as:
<xsl:variable name="ana" select="tokenize(@ana, '(\s+)')"/>
<xsl:value-of select="for $x in $ana return string-join(concat($x,':',
key('cat-by-id', $x)/catDesc), ', ')"/>
cheers
andrew
--~------------------------------------------------------------------
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>
--~--