Subject: RE: using tokenize() and referencing parent elements
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 10 May 2007 18:13:17 +0100
|
Tokenize returns strings, and strings do not have a parent.
The answer is to save the context node in a variable before going into the
for-each.
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: Spencer Tickner [mailto:spencertickner@xxxxxxxxx]
> Sent: 10 May 2007 17:52
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: using tokenize() and referencing parent elements
>
> Hi list, thanks in advance for any help.
>
> I'm using tokenize() but have to get the parent of the string
> token to determine if the string is one thing, or another. I
> came across a similiar post on the list.. but I can't seem to
> get it working with my
> case:
>
> XML
>
> <PS Class="SummaryKeyWords">
> <em>Local Governments
> Statutes Amendment Act</em>; <em>Municipal Act; Fish
> Protection Act</em>Bill 25; riparian; endangered</PS>
>
> XSL (not quite working)
>
> <xsl:template match="PS[@Class = 'SummaryKeyWords']">
> <xsl:variable name="me" select="."/>
> <keywords>
> <xsl:for-each select="tokenize(., ',|;')">
> <xsl:choose>
> <xsl:when test="$me[current()
> eq text()/parent::em]">
> <keyword><actname><xsl:value-of
> select="normalize-space(.)"/></actname></keyword>
> </xsl:when>
> <xsl:otherwise>
> <keyword><xsl:value-of
> select="normalize-space(.)"/></keyword>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:for-each>
> </keywords>
> </xsl:template>
>
> XML output wanted:
>
> <keywords>
> <keyword><actname>Local Governments Statutes Amendment
> Act</actname></keyword>
> <keyword><actname>Municipal Act</actname></keyword>
> <keyword><actname>Fish Protection Act Bill 25</actname></keyword>
> <keyword>riparian</keyword>
> <keyword>endangered</keyword>
> </keywords>
>
> XML Output I'm getting:
>
> <keywords>
> <keyword>Local Governments Statutes Amendment Act</keyword>
> <keyword>Municipal Act</keyword>
> <keyword>Fish Protection Act Bill 25</keyword>
> <keyword>riparian</keyword>
> <keyword>endangered</keyword>
> </keywords>
>
>
> Much thanks,
>
> Spencer
|