Using FXSL 1 this is straightforward:
When this transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ext="http://exslt.org/common"
exclude-result-prefixes="ext"
>
<xsl:import href="strSplit-to-Words.xsl"/>
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<xsl:key name="kWordByVal" match="word" use="."/>
<xsl:template match="/">
<xsl:variable name="vrtfwordNodes">
<words>
<xsl:call-template name="str-split-to-words">
<xsl:with-param name="pStr" select="/"/>
<xsl:with-param name="pDelimiters"
select="',
'"/>
</xsl:call-template>
</words>
</xsl:variable>
<xsl:variable name="vwordNodes"
select="ext:node-set($vrtfwordNodes)"/>
<xsl:for-each select="$vwordNodes">
<xsl:for-each select="$vwordNodes/*/*[.]
[generate-id()
=
generate-id(key('kWordByVal',.)[1])
]">
<xsl:sort data-type="number"/>
<xsl:value-of select=
"concat('Phi module ', .,
' was hit ',
count(key('kWordByVal',.)),
' times
'
)"
/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
is applied on your input document:
<phiModule>
5 5 5 5 6 6 6 6 7 7 7
7 8 8 8 8 8 5 5 5 6 6
6 7 7 7 7 7 7 7 7 8 8
8 8 8 8 8 8 8 9 9 9 9
6 7 7 7 8 8 8 8 9 9 9
9 9 9 9 9 10 10 10 10 10 10
11 11 11 11 11 9 9 9 9 9 9
9 10 10 10 10 10 10 11 11 11 11
11 11 11 11 11 11 11 12 12 13 13
13 13 13 13 13 13
</phiModule>
the wanted result is produced:
Phi module was hit 1 times
Phi module 5 was hit 7 times
Phi module 6 was hit 8 times
Phi module 7 was hit 15 times
Phi module 8 was hit 18 times
Phi module 9 was hit 19 times
Phi module 10 was hit 12 times
Phi module 11 was hit 16 times
Phi module 12 was hit 2 times
Phi module 13 was hit 8 times
Cheers,
Dimitre Novatchev
"shaun roe" <sh*******@wanadoo.frwrote in message
news:sh*****************************@cernne03.cern .ch...
>I should like to count the frequency of strings embedded in a longer
string, space separated. Specifically, I have:
<phiModule>
5 5 5 5 6 6 6 6 7 7 7
7 8 8 8 8 8 5 5 5 6 6
6 7 7 7 7 7 7 7 7 8 8
8 8 8 8 8 8 8 9 9 9 9
6 7 7 7 8 8 8 8 9 9 9
9 9 9 9 9 10 10 10 10 10 10
11 11 11 11 11 9 9 9 9 9 9
9 10 10 10 10 10 10 11 11 11 11
11 11 11 11 11 11 11 12 12 13 13
13 13 13 13 13 13
</phiModule>
And I should like to count the number of each phi value, eventually
outputting a text like:
Phi module 6 was hit 4 times.
(and so on for all the other phi values)
THe phi values are limited to a range 0-51, but I dont know what phi
values will appear in a given file.
Has anyone tackled something like this? I have to use xslt 1.0, so
tokenize, grouping etc becomes a bit tedious...
cheers
shaun