[xep-support] Need to evaluate string-lengths for a set of nodes--how?

Werner Donné werner.donne at re.be
Wed Aug 11 01:26:16 PDT 2004


Sherrod,

You can do apply-templates on the first name element. In the template
matching this you do the normal work followed by an apply-templates
on the following-sibling::name[1]. You pass the current total string
to the next as a parameter.

...
   <xsl:apply-templates select="names/name[1]"/>
...

<xsl:template match="names/name">
   <xsl:param name="current"/>
   <xsl:choose>
     <xsl:when test="string-length(.) + string-length($current) > 61">
       print a line with $current
       <xsl:choose>
         <xsl:when test="not(following-sibling::name)">
           print last line with context node
         </xsl:when>
         <xsl:otherwise>
           <xsl:apply-templates select="following-sibling::name[1]">
             <xsl:with-param name="current" select="text()"/>
           </xsl:apply-templates>
         </xsl:otherwise>
       </xsl:choose>
     </xsl:when>
     <xsl:when test="not(following-sibling::name)">
       print last line with $current and context node
     </xsl:when>
     <xsl:otherwise>
       <xsl:apply-templates select="following-sibling::name[1]">
         <xsl:with-param name="current" select="concat($current, text())"/>
       </xsl:apply-templates>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

Regards,

Werner.

Blankner, Sherrod wrote:
> 	Can anyone out there help me brainstorm some logic for a letter
> recipient name:
> 
> 	We have a simple letter XSL that processes the following XML to fill
> in the recipient name
> 	<names>
> 		<name>John Doe</name>
> 		<name>Jane Doe</name>
> 		<name>Jim Doe</name>
> 		</names>
> 
> 	Currently our XSL is very straight forward
> 
> 			<fo:block>
> 				<xsl:for-each select="names/name">
> 					<fo:block>
> 						<xsl:value-of select="."/>
> 					</fo:block>
> 				</xsl:for-each>
> 				</fo:block>
> 
> 
> However, with the new window size in the envelope, we can't stack names
> indefinitely--we only have 6 lines for the total address, with a maximum of
> three name lines if the address is in the US. I need logic that evaluates
> whether the string length of a set of <name> tags is more than 61
> characters, at which point I want to cut off and print just those names into
> line 1. Then I need to start where line 1 left off and evaluate the next set
> of <name> tags and see if these add up to under 61 characters, at which
> point I can write in line 2, etc. I have three possible lines.
> 
> Does anyone have any suggestions?
> I've been working with the string-length function, but I can't seem to get
> it to increment up inside a for-each loop. I also messed around with some
> param/call-templates functions but got the same result. 
> 
> Thanks
> Sherrod
> 
> 
> 
> 
> 
> Sherrod Blankner
> CRS Digital Studio
> ---------------------------------------------------
> 120 Kearny, 11th Floor
> Desk: 415-636-5181
> Cell: 415-225-9159
> ---------------------------------------------------
> 
> -------------------
> (*) To unsubscribe, send a message with words 'unsubscribe xep-support'
> in the body of the message to majordomo at renderx.com from the address
> you are subscribed from.
> (*) By using the Service, you expressly agree to these Terms of Service http://www.renderx.com/tos.html
> 
> 

-- 
Werner Donné  --  Re BVBA
Engelbeekstraat 8
B-3300 Tienen
tel: (+32) 486 425803	e-mail: werner.donne at re.be

-------------------
(*) To unsubscribe, send a message with words 'unsubscribe xep-support'
in the body of the message to majordomo at renderx.com from the address
you are subscribed from.
(*) By using the Service, you expressly agree to these Terms of Service http://www.renderx.com/tos.html



More information about the Xep-support mailing list