[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: Alice Ju-Hsuan Wei <ajwei@xxxxxxxxxxx>
Date: Sun, 21 Oct 2007 21:54:20 -0400
RE: Counting Child Nodes?
Dear Michael and all:

Like you said, now the code is working. I had used an <xsl:value-of select="string-length(child::p)"> to count the every single element inside the template, and it turns out that the number matches the ones I have in the above code. I forgot to mention that I do use XSLT 1.0, but there is a problem here (I am not sure if this is the one you are suspecting).

When I run the XSLT and ask it to report back to the string length, every single one reported back matches the template below. Yes, like you said, when there are matches that may be in two paragraphs, but the first <p> is less than 20 characters long, it brings me back not the result in the third condition, but the first one.
So, here is the code I had implemented with the most problematic portions:


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;100) and 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 test="string-length(child::p) &gt; 100 ">
<xsl:attribute name="style"> background-image:url('<xsl:value-of
select="./@rendition"/>_large.png') </xsl:attribute>
</xsl:if>
<xsl:if
test="(count(child::p) &gt; 1) or (string-length(child::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>


If the count function does not take the entire <p> tag in the sense you thought I was thinking of, what might be other approaches? Following-sibling:?

Thanks in advance.

Alice.

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-2011 All Rights Reserved.