From: Blankner, Sherrod (Sherrod.Blankner@schwab.com)
Date: Fri Aug 13 2004 - 14:47:55 PDT
Werner:
We sorted it out--turned out to be much more elaborate than we thought, but
your suggestion of following-sibling was key. I was thinking in terms of
preceding, but that wasn't going to work. We had to get very elaborate to
account for commas and the use of "and" between names, but other than that
it was okay. Had to do a line counter to keep track of how many lines we
were allowed to use.
Here's the code we developed, in case you're interested. Thanks!
Sherrod
<xsl:template name="maxLineCounter"> <xsl:choose> <xsl:when test="/package/recipient/address2=''"> <xsl:choose> <xsl:when test="( normalize-space( country )
= 'US' and not ( starts-with( state, 'A#' ) ) )"> <xsl:value-of select="4"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="3"/> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:choose> <xsl:when test="( normalize-space( country )
= 'US' and not ( starts-with( state, 'A#' ) ) )"> <xsl:value-of select="3"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="2"/> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </xsl:template> <!-- commaFinder --> <xsl:template name="commaFinder"> <xsl:param name="oldCopy"/> <xsl:param name="width"/> <xsl:choose> <xsl:when test="substring($oldCopy,$width,1) = ','"> <xsl:value-of select="$width"/> </xsl:when> <xsl:otherwise> <xsl:call-template name="commaFinder"> <xsl:with-param select="$oldCopy"
name="oldCopy"/> <xsl:with-param select="$width - 1"
name="width"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> <!-- copyChopper --> <xsl:template name="copyChopper"> <xsl:param name="startPosition"/> <xsl:param name="maxLineCount"/> <xsl:param name="lineCount"/> <xsl:param name="oldCopy"/> <xsl:param name="purpose"/> <xsl:variable name="addressLineWidth">60</xsl:variable> <xsl:choose> <xsl:when
test="/package/recipient/names/name[position() = $startPosition + 1]"> <xsl:if
test="($lineCount < $maxLineCount) and
/package/recipient/names/name[position() = $startPosition + 2]">
<xsl:variable name="lessMax2Fol" select="normalize-space(concat($oldCopy,',
',/package/recipient/names/name[position() = $startPosition +
1]))"></xsl:variable>
<xsl:choose>
<xsl:when test="string-length($lessMax2Fol) < $addressLineWidth">
<xsl:call-template name="copyChopper">
<xsl:with-param select="$startPosition + 1" name="startPosition"/>
<xsl:with-param select="$maxLineCount" name="maxLineCount"/>
<xsl:with-param select="$lineCount" name="lineCount"/>
<xsl:with-param select="$lessMax2Fol" name="oldCopy"/>
<xsl:with-param select="'getCopy'" name="purpose"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$purpose = 'getStartPosition'">
<xsl:value-of select="$startPosition + 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(normalize-space($oldCopy),',','
')"/>
<xsl:call-template name="format">
<xsl:with-param select="$maxLineCount" name="maxLineCount"/>
<xsl:with-param select="$lineCount + 1" name="lineCount"/>
<xsl:with-param select="$startPosition + 1" name="startPosition"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose> </xsl:if> <xsl:if
test="($lineCount < $maxLineCount) and
not(/package/recipient/names/name[position() = $startPosition + 2])">
<xsl:variable name="lessMax1Fol" select="normalize-space(concat($oldCopy,'
and ',/package/recipient/names/name[position() = $startPosition +
1]))"></xsl:variable>
<xsl:choose>
<xsl:when test="string-length($lessMax1Fol) < $addressLineWidth">
<xsl:choose>
<xsl:when test="$purpose = 'getStartPosition'">
<xsl:value-of select="$startPosition + 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$lessMax1Fol"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$purpose = 'getStartPosition'">
<xsl:value-of select="$startPosition + 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(normalize-space($oldCopy),',','
')"/>
<xsl:call-template name="format">
<xsl:with-param select="$maxLineCount" name="maxLineCount"/>
<xsl:with-param select="$lineCount + 1" name="lineCount"/>
<xsl:with-param select="$startPosition + 1" name="startPosition"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose> </xsl:if> <xsl:if
test="($lineCount = $maxLineCount) and
/package/recipient/names/name[position() = $startPosition + 2]">
<xsl:variable name="EqMax2Fol" select="normalize-space(concat($oldCopy,',
',/package/recipient/names/name[position() = $startPosition +
1]))"></xsl:variable>
<xsl:choose>
<xsl:when test="string-length($EqMax2Fol) < $addressLineWidth">
<xsl:call-template name="copyChopper">
<xsl:with-param select="$startPosition + 1" name="startPosition"/>
<xsl:with-param select="$maxLineCount" name="maxLineCount"/>
<xsl:with-param select="$lineCount" name="lineCount"/>
<xsl:with-param select="$EqMax2Fol" name="oldCopy"/>
<xsl:with-param select="'getCopy'" name="purpose"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$purpose = 'getStartPosition'">
<xsl:value-of select="$startPosition + 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains(normalize-space($oldCopy),',')">
<xsl:variable name="commaLocation">
<xsl:call-template name="commaFinder">
<xsl:with-param select="$oldCopy" name="oldCopy"/>
<xsl:with-param select="$addressLineWidth" name="width"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="oldCopyRedone"
select="normalize-space(concat(substring($oldCopy,1,$commaLocation - 1),'
and ',substring($oldCopy,$commaLocation + 1)))"/>
<xsl:value-of select="normalize-space($oldCopyRedone)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(concat('and ',$oldCopy))"/>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="format">
<xsl:with-param select="$maxLineCount" name="maxLineCount"/>
<xsl:with-param select="$lineCount + 1" name="lineCount"/>
<xsl:with-param select="$startPosition + 1" name="startPosition"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose> </xsl:if> <xsl:if
test="($lineCount = $maxLineCount) and
not(/package/recipient/names/name[position() = $startPosition + 2])">
<xsl:variable name="equalMax1Fol" select="normalize-space(concat($oldCopy,'
and ',/package/recipient/names/name[position() = $startPosition +
1]))"></xsl:variable>
<xsl:choose>
<xsl:when test="string-length($equalMax1Fol) < $addressLineWidth">
<xsl:choose>
<xsl:when test="$purpose = 'getStartPosition'">
<xsl:value-of select="$startPosition + 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$equalMax1Fol"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$purpose = 'getStartPosition'">
<xsl:value-of select="$startPosition + 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('and ',normalize-space($oldCopy),'
')"/>
<xsl:call-template name="format">
<xsl:with-param select="$maxLineCount" name="maxLineCount"/>
<xsl:with-param select="$lineCount + 1" name="lineCount"/>
<xsl:with-param select="$startPosition + 1" name="startPosition"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose> </xsl:if> </xsl:when> <xsl:otherwise> <xsl:choose> <xsl:when test="$purpose =
'getStartPosition'"> <xsl:value-of
select="$startPosition + 1"/> </xsl:when> <xsl:otherwise> <xsl:value-of
select="normalize-space(concat('and
',/package/recipient/names/name[position() = $startPosition]))"/> </xsl:otherwise> </xsl:choose>
</xsl:otherwise> </xsl:choose> </xsl:template> <!-- FORMAT --> <xsl:template name="format"> <xsl:param name="maxLineCount"/> <xsl:param name="lineCount"/> <xsl:param name="startPosition"/> <xsl:if test="$lineCount <= $maxLineCount"> <xsl:variable name="startPositionVariable"> <xsl:call-template name="copyChopper"> <xsl:with-param
select="$startPosition" name="startPosition"/> <xsl:with-param
select="$maxLineCount" name="maxLineCount"/> <xsl:with-param select="$lineCount"
name="lineCount"/> <xsl:with-param select="''"
name="oldCopy"/> <xsl:with-param
select="'getStartPosition'" name="purpose"/> </xsl:call-template> </xsl:variable> <xsl:variable name="copyVariable"> <xsl:call-template name="copyChopper"> <xsl:with-param
select="$startPosition" name="startPosition"/> <xsl:with-param
select="$maxLineCount" name="maxLineCount"/> <xsl:with-param select="$lineCount"
name="lineCount"/> <xsl:with-param
select="/package/recipient/names/name[position() = $startPosition]"
name="oldCopy"/> <xsl:with-param select="'getCopy'"
name="purpose"/> </xsl:call-template> </xsl:variable> <fo:block linefeed-treatment="preserve"
wrap-option="no-wrap"> <xsl:value-of select="$copyVariable"/> </fo:block> </xsl:if> </xsl:template> <xsl:template name="namesParser"> <xsl:variable name="maxLineCount"> <xsl:call-template name="maxLineCounter"> </xsl:call-template> </xsl:variable> <xsl:call-template name="format"> <xsl:with-param select="$maxLineCount"
name="maxLineCount"/> <xsl:with-param select="1" name="lineCount"/> <xsl:with-param select="1" name="startPosition"/> </xsl:call-template> </xsl:template>
The original "namesParser" template is called by a small call-templates code
in side a table cell
<xsl:call-template name="namesParser"></xsl:call-template>
> ----------
> From: owner-xep-support@renderx.com on behalf of Blankner, Sherrod
> Reply To: xep-support@renderx.com
> Sent: Wednesday, August 11, 2004 9:29 AM
> To: 'xep-support@renderx.com'
> Subject: RE: [xep-support] Need to evaluate string-lengths for a set
> of no des--how?
>
> Werner:
> Thanks for your reply! I was messing around with preceding sibing, but
> following-sibling may do the trick. I'll let you know how it progresses.
> skb
>
> > ----------
> > From: owner-xep-support@renderx.com on behalf of Werner Donné
> > Reply To: xep-support@renderx.com
> > Sent: Wednesday, August 11, 2004 1:26 AM
> > To: xep-support@renderx.com
> > Subject: Re: [xep-support] Need to evaluate string-lengths for a set
> > of nodes--how?
> >
> > 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@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@re.be
> >
> > -------------------
> > (*) To unsubscribe, send a message with words 'unsubscribe xep-support'
> > in the body of the message to majordomo@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
> >
> >
>
> -------------------
> (*) To unsubscribe, send a message with words 'unsubscribe xep-support'
> in the body of the message to majordomo@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
>
>
-------------------
(*) To unsubscribe, send a message with words 'unsubscribe xep-support'
in the body of the message to majordomo@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
This archive was generated by hypermail 2.1.5 : Fri Aug 13 2004 - 15:04:36 PDT