There were so many problems with your previous code that we may have failed
to spot the one that was causing the trouble. I'm a bit reluctant to offer
more advice since you haven't yet implemented the suggestions I already
made, however:
Your <book> element has two <p> children. Therefore in the expression
string-length(child::p)<'75'
assuming that the context node is the <book> element, an XSLT 2.0 processor
will report an error because the argument of string-length must be a single
value. (If the context node isn't the <book>, then child::p makes even less
sense.) A 1.0 processor will simply take the length of the first p child.
This doesn't seem to be what you had in mind.
Michael Kay
http://www.saxonica.com/
-----Original Message-----
From: Alice Ju-Hsuan Wei [mailto:ajwei(_at_)indiana(_dot_)edu]
Sent: 21 October 2007 15:40
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl]Counting Child Nodes?
Hi,
Thanks to all of you who helped pitch in to make this code
work. Now, this code is basically working, but I don't know
why it generates the background image as either _med.png or
_large.png, while those with string length smaller than 25
characters still generate the second <xsl:if> statement, by
generating the _med.png just the same as the second condition.
Is this another boolean problem I am having? Any suggestions?
Thanks in advance.
Alice
XML:
<book topic="Technology" rendition="xslt" author="Tennison, Jeni"
title="Beginning XSLT">
<p>New York: Apress, 2002.</p>
<p>The book serves as an introduction to XSLT based on
the examples of a television program set. A resourceful book
for those new to the technology.</p>
</book>
XSLT:
<xsl:choose>
<xsl:when test="$rendition!=''">
<div>
<xsl:attribute name="class">
<xsl:value-of select="$rendition"/>
</xsl:attribute>
<xsl:if
test="string-length(child::p)<'25'">
<xsl:attribute name="style">
background-image:url('<xsl:value-of
select="./@rendition"/>.png') </xsl:attribute>
</xsl:if>
<xsl:if
test="string-length(child::p)<'75'">
<xsl:if
test="string-length(child::p)>'25'">
<xsl:attribute
name="style"> background-image:url('<xsl:value-of
select="./@rendition"/>_med.png') </xsl:attribute>
</xsl:if>
</xsl:if>
<xsl:if
test="(count(child::p) > '1') or
(string-length(p) > '100') ">
<xsl:attribute name="style">
background-image:url('<xsl:value-of
select="./@rendition"/>_large.png') </xsl:attribute>
</xsl:if>
<p>
<xsl:call-template name="rend"/>
<xsl:apply-templates/>
</p>
</div>
</xsl:when>
<xsl:otherwise>
<span>
<xsl:call-template name="rend"/>
<xsl:apply-templates/>
</span>
</xsl:otherwise>
</xsl:choose>
--~------------------------------------------------------------------
XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--