472,986 Members | 2,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 software developers and data experts.

Histogram in XSLT 1.0

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
Nov 27 '06 #1
4 1879
I have to use xslt 1.0

Why?
tokenize, grouping etc becomes a bit tedious...
Sure does. Kinda sounds like an arbitrary academic
homework assignment, in which case an arbitrary
academic solution should suffice.

I guess I would look into transforming the numeric
list into a set of XML nodes (e.g. "<Foo Phi='xx'/>")
and then for-each of the possible values of phi, just
emit a count of the nodes having the attribute of
the corresponding value.

Good luck,
Ron Burk
www.xmlator.com

Nov 27 '06 #2
xm*****@gmail.com wrote:
>>I have to use xslt 1.0
Why?
Presumably because a 2.0 processor isn't available in the target
environment (not very surprising).

Since XSLT's string (as opposed to structural) manipulation capabilities
are relatively limited, I agree that the two-stage approach (convert it
into something XSLT can count easily, then count) may be simplest. That
second pass can be done in 1.0 without a separate styling pass with a
bit of help from the exslt nodeset extension function; this isn't
actually part of 1.0 but it is widely supported for exactly this sort of
two-pass solution.

Of course you're going to have to do a recursive parse pass to pull the
individual integers out of that text string and convert them. So another
approach would be to write the recursion to count them directly and
generate a report when it runs out of input. You know there's a limited
range, so you can have an explicit parameter for each value to carry the
count (so far) down through the recursion. Since this would be
tail-recursion, a good XSLT processor would be able to optimize it into
a tolerably efficient loop.

Another fix, of course, would be to change whatever is generating this
data to produce it in a more XML/XSLT-friendly format in the first
place, avoiding the need for conversion or tokenizing.


--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Nov 27 '06 #3
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&#xA;'
)"
/>
</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

Nov 28 '06 #4
In article <456b7103$1@kcnews01>,
Joseph Kesselman <ke************@comcast.netwrote:
xm*****@gmail.com wrote:
>I have to use xslt 1.0
Why?

Presumably because a 2.0 processor isn't available in the target
environment (not very surprising).

Since XSLT's string (as opposed to structural) manipulation capabilities
are relatively limited, I agree that the two-stage approach (convert it
into something XSLT can count easily, then count) may be simplest. That
second pass can be done in 1.0 without a separate styling pass with a
bit of help from the exslt nodeset extension function; this isn't
actually part of 1.0 but it is widely supported for exactly this sort of
two-pass solution.

Of course you're going to have to do a recursive parse pass to pull the
individual integers out of that text string and convert them. So another
approach would be to write the recursion to count them directly and
generate a report when it runs out of input. You know there's a limited
range, so you can have an explicit parameter for each value to carry the
count (so far) down through the recursion. Since this would be
tail-recursion, a good XSLT processor would be able to optimize it into
a tolerably efficient loop.

Another fix, of course, would be to change whatever is generating this
data to produce it in a more XML/XSLT-friendly format in the first
place, avoiding the need for conversion or tokenizing.
Thanks for the ingenious suggestions and solutions. I should explain the
context, maybe you will find it interesting; I am working on the Silicon
Tracker for the Atlas experiment at CERN. I am seriously considering
proposing XSLT (dare I say Ajax?) as a remote monitoring solution for
the experiment, the idea being that only the Firefox web browser would
be needed to see the results. An example of a cosmic ray event is here:

http://sroe.home.cern.ch/sroe/svg/combined.svg

(generated by XSLT)

Thus I am restricted to what might be achievable in Firefox, with or
without some scripting incorporated. The file I showed generates the
kind of event display I link to, so is not *really* ideal for
histogramming, but seems (at present) to be the only xml result file
available as an RPC request from our analysis program. I'm trying to
discover how much I can do with it. In particular, where SVG production
is not an option I want a text summary of the event.
I can see I should make an effort to get the more amenable result files
available on request via a web service, but your suggestions have given
me some ideas for working with what I've got...

cheers

shaun
Nov 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Oracle3001 | last post by:
Hi All, I am trying to use JAI to build a histogram of an image i have. I have posted the code below, and the error I get at runtime. I have taken the code from the offical java examples, so I am...
1
by: bleh | last post by:
....to include a removeData(datatoremove) function, to mirror the existing addData(datatoadd) function. If anybody knows of somewhere where this has been done already, if you could point me in...
27
by: ext_u | last post by:
Ok I thought I would try to take the program one thing at a time. (If you remember my last post I am trying to make a histogram with data on the size of each word) Anways first .. I obviously...
12
by: KraftDiner | last post by:
Hi, I wrote a C++ class that implements an n dimensional histogram in C++, using stl maps and vectors. I want to code this up now in Python and would like some input from this group. The C++...
5
by: Enigma Curry | last post by:
I'm playing around with matplotlib for the first time. I'm trying to make a very simple histogram of values 1-6 and how many times they occur in a sequence. However, after about an hour of...
2
by: Daniel Nogradi | last post by:
How does one do a histogram on only a part of an image? This is what I found in the PIL documentation about histogram( ): """ im.histogram(mask) =list Returns a histogram for those parts of...
5
by: arnuld | last post by:
this is a programme that counts the "lengths" of each word and then prints that many of stars(*) on the output . it is a modified form of K&R2 exercise 1-13. the programme runs without any...
12
by: arnuld | last post by:
i was able to create a solution for a Horizontal-Histogram. i was completely unable to understand this Vertical-Histogram phenomenon. even though i have looked at the solution at this page: ...
1
by: avenger3200 | last post by:
Hello everyone, I am trying to make a histogram for a project in my class and I really need some help. Here is the question that my instructor provided: Create 1000 Random numbers between...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.