472,811 Members | 1,211 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,811 software developers and data experts.

XSLT - counting the number of xsl:if which are true...

OK, total newbie here, so this may be a mind-numbingly dumb question AND
I may be phrasing it badly.

I have an xsl:template which looks like this:

<xsl:template match="LoanRecord">
<hr>
<xsl:number count="LoanRecord" format="1"/><br/>
Loan ID:<xsl:value-of select="loan_no"> </xsl:value-of><br/>
Calculated CLTV:<xsl:value-of select="format-number (curr_balance div
orig_amount,'##%')"> </xsl:value-of>
<xsl:if test="(number(curr_balance div orig_amount) &gt; 0.8)">
<i> (High LTV)</i>
</xsl:if>
</hr>
</xsl:template>

In short, it prints some data from the input file, and calculates a
value, and, if that value is above a certain value, it also outputs a
warning message.

This works.

What I want, though, is to have several xsl:if statements in there, and,
at the end, to tally all those who evaluated to true. However, there
seems to be no way to easily keep a running count of things. I am slowly
begining to suspect this is by design. I am also aware I haven't fully
inhaled the full syntax and function library of xslt, much less grokked
all the cool things which can be done with it, so I am wondering if I
might be missing something. (I know I can easily count all the nodes
which meet a given condition; what I want to do is, within a record,
check for 'n' conditions and then count the total number of conditions
satisfied.)

Jul 20 '05 #1
3 3843
Have you tried <xsl:choose> ?

Lizard wrote:
OK, total newbie here, so this may be a mind-numbingly dumb question AND
I may be phrasing it badly.

I have an xsl:template which looks like this:

<xsl:template match="LoanRecord">
<hr>
<xsl:number count="LoanRecord" format="1"/><br/>
Loan ID:<xsl:value-of select="loan_no"> </xsl:value-of><br/>
Calculated CLTV:<xsl:value-of select="format-number
(curr_balance div orig_amount,'##%')"> </xsl:value-of>
<xsl:if test="(number(curr_balance div orig_amount) &gt; 0.8)">
<i> (High LTV)</i>
</xsl:if>
</hr>
</xsl:template>

In short, it prints some data from the input file, and calculates a
value, and, if that value is above a certain value, it also outputs a
warning message.

This works.

What I want, though, is to have several xsl:if statements in there, and,
at the end, to tally all those who evaluated to true. However, there
seems to be no way to easily keep a running count of things. I am slowly
begining to suspect this is by design. I am also aware I haven't fully
inhaled the full syntax and function library of xslt, much less grokked
all the cool things which can be done with it, so I am wondering if I
might be missing something. (I know I can easily count all the nodes
which meet a given condition; what I want to do is, within a record,
check for 'n' conditions and then count the total number of conditions
satisfied.)


Jul 20 '05 #2
What about this:

<xsl:variable name="vHits">
<xsl:if test="expression1">1</xsl:if>
<xsl:if test="expression2">1</xsl:if>
. . . . . . . . . .
<xsl:if test="expressionN">1</xsl:if>
</xsl:variable>

<xsl:variable name="vhitCount" select="string-length($vHits)"/>
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
"Lizard" <li****@mrlizard.com> wrote in message
news:3F************@mrlizard.com...
OK, total newbie here, so this may be a mind-numbingly dumb question AND
I may be phrasing it badly.

I have an xsl:template which looks like this:

<xsl:template match="LoanRecord">
<hr>
<xsl:number count="LoanRecord" format="1"/><br/>
Loan ID:<xsl:value-of select="loan_no"> </xsl:value-of><br/>
Calculated CLTV:<xsl:value-of select="format-number (curr_balance div
orig_amount,'##%')"> </xsl:value-of>
<xsl:if test="(number(curr_balance div orig_amount) &gt; 0.8)">
<i> (High LTV)</i>
</xsl:if>
</hr>
</xsl:template>

In short, it prints some data from the input file, and calculates a
value, and, if that value is above a certain value, it also outputs a
warning message.

This works.

What I want, though, is to have several xsl:if statements in there, and,
at the end, to tally all those who evaluated to true. However, there
seems to be no way to easily keep a running count of things. I am slowly
begining to suspect this is by design. I am also aware I haven't fully
inhaled the full syntax and function library of xslt, much less grokked
all the cool things which can be done with it, so I am wondering if I
might be missing something. (I know I can easily count all the nodes
which meet a given condition; what I want to do is, within a record,
check for 'n' conditions and then count the total number of conditions
satisfied.)

Jul 20 '05 #3
Dimitre Novatchev wrote:
What about this:

<xsl:variable name="vHits">
<xsl:if test="expression1">1</xsl:if>
<xsl:if test="expression2">1</xsl:if>
. . . . . . . . . .
<xsl:if test="expressionN">1</xsl:if>
</xsl:variable>

<xsl:variable name="vhitCount" select="string-length($vHits)"/>

Looks interesting...I will try that. Thanks!

Jul 20 '05 #4

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

Similar topics

3
by: Steven | last post by:
I'm using XSL to transform an XML document to HTML, however I'm encountering the following problem.I want to test a couple of values using an xsl:if statement and then print a couple of HTML tags...
9
by: Andrea Maschio | last post by:
Hi, i have a terrible noobie frustration formatting an XML file like this: <Dipendente Id="1" Anno="2003" Nome="pippo" Cognome="pippi" Nato_il="10/03" Email="pippo@emailprovider.it" Esito="ok"/>...
3
by: Eric Theil | last post by:
I'm at my wit's end with this one. Within an xsl:if test, I'm not able to get 2 variables to properly evaluate if one of them is wrapped within a string function. <!-- This works --> <xsl:if...
2
by: websls | last post by:
I tried to do this : <xsl:if test="ToutCompris"> some output </xsl:if> ToutCompris is a boolean element in my XML file My problem is the output is parse even when ToutCompris is false I...
3
by: tldisbro | last post by:
Hello All, I am trying to use the returned value of the <fo:page-number> element/function in my <xsl:if> test condition. But am unsuccessful in doing so. Is it possible to use it in this fashion...
2
by: riceyeh | last post by:
Hi, What does <xsl:if test="not($values)"mean? What I do not understand is $values? Here, means array? And . = $value means current node is equal to the variable value? So the total meaning is...
1
by: Fred | last post by:
Hi, I am using XSL if to look and see if a node exists and if so display it with a header (see below). Some of the xml I transforming has nodes like this <Test /and it shows up in my html...
4
by: Doulos05 | last post by:
Ok, this seems like it should be easy, but it has escaped me. Here is my xml file: <ref_sheet> <item> <date>2007/04/06</date> <product>124567</product> <description>TAB...
3
by: z1 | last post by:
hi- i am fooling around with soap and weather templates. for some reason either this if or select is failing. i am very new to xml and found this code at another site. i can show you the xml...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
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=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
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...

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.