Click to See Complete Forum and Search --> : if (count empty tags) = a_number


tyris
July 16th, 2001, 04:18 AM
hi all
i do have a xml structure this way :

<results dbname="Marketings">
<searchview name="Doc">
<result>
<url>http://etc</url>
<icon>150</icon>
<icon>171</icon>
<description>abcdef</description>
</result>
<result>
<url>http://etc</url>
<icon></icon>
<icon>172</icon>
<description>jaehdeg</description>
</result>
<result>
<url>http://etc</url>
<icon></icon>
<icon></icon>
<description>adhthsdgz</description>
</result>
</searchview>
</results>


what i want is :
if ALL the icon tags are empty, put the description in
bold, else do not put the description in bold and put the
icon url.

my namespace is http://www.w3.org/1999/XSL/Transform"; (MS
XSL 3)

i have found how to test an empty tag :

<xsl:for-each select="icon">
<xsl:choose>
<xsl:when test='. != ""'>
blah...
</xsl:when>
<xsl:otherwise>
blah...
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>

now for the test : "if ALL icon tag are empty do this" i
think that i should do something like :
<xsl:for-each select="result">
if ... count(icon!="") = 2 then ...
</xsl:for-each>

(because i will never have more than 2 icon tags, empty or
not)

but how to do this ? i tryed this first test:
<xsl:for-each select="result">
<xsl:value-of select='count(icon!="")'/>
</xsl:for-each>

and i do get this error : Expression does not return a DOM
node. -->count(icon!="")<-- (???)

so here is a first problem (what's wrong with my count
function ?). second question : how to use the count result
in a test like what i wrote above ( if (result of count) =
2 then..)

any help would be appreciated

sorry for my english, i'm french

regards ;-)

elise

tyris
July 16th, 2001, 04:37 AM
i do have a begin of solution but...

well i tryed this :

<xsl:for-each select="result">
<xsl:choose>
<xsl:when test='count(result[icon=""]) = 2'>
here i put in bold
</xsl:when>
<xsl:otherwise>
blah
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>

the problem is that count(result[icon=""]) always returns me 0. i guess there is a syntax problem, but where ?


regards ;-)

elise

tyris
July 16th, 2001, 10:00 AM
i found what i wanted to do :


<xsl:when test='("" != icon) = false'>


regards ;-)

elise

dressegu
July 16th, 2001, 10:22 AM
This:
<xsl:when test='count(result[icon=""]) = 2'>

is looking for a result tag inside the already selected result tag.

That's why you were getting 0.

dressegu
July 16th, 2001, 10:24 AM
Shouldn't this:
<xsl:value-of select='count(icon!="")==2'/>

be this:

<xsl:value-of select='count(icon[.=""]) ==2'/>

I'm a bit rusty on my XSL and I didn't take the time to test this, but you get the idea.

David