xsl-list
[Top] [All Lists]

RE: [xsl]Counting Child Nodes?

2007-10-21 18:54:55
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.

--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>