Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   XSLT - counting the number of xsl:if which are true... (http://www.velocityreviews.com/forums/t165805-xslt-counting-the-number-of-xsl-if-which-are-true.html)

Lizard 10-06-2003 11:32 PM

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.)


Karthik.S 10-07-2003 04:10 AM

Re: XSLT - counting the number of xsl:if which are true...
 
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.)
>



Dimitre Novatchev 10-07-2003 04:45 AM

Re: XSLT - counting the number of xsl:if which are true...
 
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" <lizard@mrlizard.com> wrote in message
news:3F81FB91.20206@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.)
>




Lizard 10-07-2003 10:51 PM

Re: XSLT - counting the number of xsl:if which are true...
 
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!



All times are GMT. The time now is 03:15 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57