Subject: Re: [xsl] tokenize From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 14 Oct 2011 09:00:46 -0400 |
It's either my brain slowing down, or the fact that it's nearly the weekend, or my lack of sleep and coffee, but I can't understand this: I need to break up the content of a td element which represents a Unix filepath, tokenizing on slashes, and getting rid of bogus visual formatting:
<xsl:template match="h:tbody/h:tr"> <!-- tokenise the uri so that we only extract valid data, eg <td class="xl">     /researchprofiles/A015/pcrowley/</td> --> <xsl:variable name="uri"> <xsl:value-of select="translate(h:td[@class='xl'],' 
','')"/> </xsl:variable>
<xsl:variable name="uri" select="translate(h:td[@class='x1'],' 
','')"/>
<xsl:variable name="urifrag" select="tokenize($uri,'/')"/> <xsl:text>"</xsl:text> <xsl:value-of select="$urifrag[1]"/> <xsl:text>" </xsl:text> <xsl:text>
</xsl:text> ... </xsl:template>
(the commented example is Tidy'd output from the 'analog' web logfile analyser). The result for the example td element is output as:
"/researchprofiles/A015/pcrowley"
~/t/ftemp $ cat peter.xsl <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="/"> <xsl:variable name="in"> <xsl:value-of select="' 

 /researchprofiles/A015/pcrowley/'"/> </xsl:variable> <xsl:variable name="uri" select="translate($in,' 
','')"/> <xsl:variable name="urifrag" select="tokenize($uri,'/')"/> Tokens: <xsl:for-each select="$urifrag"> <xsl:value-of select="concat('*',.,'* ')"/> </xsl:for-each> End </xsl:template> </xsl:stylesheet> ~/t/ftemp $ xslt2 peter.xsl peter.xsl <?xml version="1.0" encoding="UTF-8"?> Tokens: ** *researchprofiles* *A015* *pcrowley* ** End ~/t/ftemp $
In other words, not only has it not tokenized the string, but something has gobbled the trailing slash from the input content. I suspected that there was some character encoding error (slashes except the final one not being real slashes, perhaps) but they are all genuine.
I have clearly misunderstood how tokenize works (except that I have been using it perfectly happily elsewhere for years). The variable $urifrag seems to be returning the entire string rather than breaking it up, except for the trailing slash, which means it is actually splitting the string on its final slash only, instead of on all slashes.
From that, I deduce that I have mis-expressed the variable or the function, but it isn't apparent where or how.
-- Contact us for world-wide XML consulting and instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] tokenize, Martin Honnen | Thread | Re: [xsl] tokenize, Peter Flynn |
Re: [xsl] tokenize, Martin Honnen | Date | Re: [xsl] tokenize, Peter Flynn |
Month |