[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Counting Child Nodes?

Subject: RE: Counting Child Nodes?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 22 Oct 2007 00:21:24 +0100
RE: Counting Child Nodes?
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)&lt;'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@xxxxxxxxxxx] 
> Sent: 21 October 2007 15:40
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: 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)&lt;'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)&lt;'75'">
>                                 <xsl:if 
> test="string-length(child::p)&gt;'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) &gt; '1') or
> (string-length(p) &gt; '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>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.