Modifying variables

R

requeth

I have 12 possible error codes that can be placed in an attribute, and
multiple attributes with this in an XML file. I am attempting to use an
XSLT (which makes the data viewable to non technical people) to display
some statistics about these error codes. Specifically, how many of each
type there are. My thought was to create some code using variables, and
do $err01+1 (or ++), but as far as I can tell you are not allowed to
manipulate variables once called. Are any functions available that
would let me complete a count of each error type, and output them each
individually? The only bad solution I had was every time it found an
error code, create a variable +1 on the name and count them all up
after, but that's horrific to me.

Any thoughts would help,

Thanks
 
J

Joe Kesselman

Yes. XSLT variables are single-assignment.

The best answer is to come up with an XPath expression which finds all
the errors of a given type and ask it how long its result set is. (Use
XSLT's own counts rather than trying to compute your own.)

If you absolutely must do your own counting, you'll have to code it as a
recursive template call, using a template parameter as your counter and
calling back into the template to assign a new value to it. Can be done,
but generally ugly and inefficient and considered an absolute last resort.

See the XSL FAQ website's sections counting and numbering for some code
examples:
http://www.dpawson.co.uk/xsl/sect2/sect21.html
 
R

requeth

That was very helpful, thank you. I always love finding out a built in
function exists while I'm preparing to reinvent the wheel.

Tim :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top