|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: conditional count
Please try this XSL -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/root">
<xsl:variable name="x">
<xsl:for-each select="row">
<xsl:variable name="y">
<xsl:for-each select="column">
<xsl:if test="normalize-space(.) != ''">
1
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:if
test="(string-length(normalize-space($y)) -
string-length(translate(normalize-space($y), '1',
''))) = count(column)">
2
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:value-of
select="string-length(normalize-space($x)) -
string-length(translate(normalize-space($x), '2',
''))"/>
</xsl:template>
</xsl:stylesheet>
Regards,
Mukul
--- Daniel Heskia <daniel@xxxxxxxxx> wrote:
> Hi.
> I have some unhandy xml that I would like to process
> in plain xsl by
> counting elements conditionally (if the entire data
> set in the elemt is
> full).
> In the example below I want to count only the number
> of element "row" where
> all underlying columns have data. i.e. the number in
> the example should be
> 1.
>
> I can filter out the empty "row"'s by challenging
> the contents of the entire
> element by:
> <xsl:value-of
> select="count(/root/row[normalize-space()])"/>
>
> But how do I exclude an element "row" if just a
> single "column" in the
> element is empty?
>
> <root>
> <row>
> <column>Peter</column>
> <column>Johnson</column>
> <column>High Street 10</column>
> <column>Male</column>
> <column>15-10-2004</column>
> <column>13.11</column>
> </row>
> <row>
> <column></column>
> <column></column>
> <column></column>
> <column></column>
> <column></column>
> <column></column>
> </row>
> <row>
> <column>Sue</column>
> <column>Bond</column>
> <column>Dollar Avenue</column>
> <column>Female</column>
> <column>01-05-2003</column>
> <column></column>
> </row>
> </root>
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








