[xsl] string replace with ­

Subject: [xsl] string replace with ­
From: "Miller, James V (CRD)" <millerjv@xxxxxxxxxx>
Date: Fri, 2 Nov 2001 10:42:49 -0500
I have an XML file that I am converting to HTML. In the processing, I have a string of the form
"machine.site.domain".  These strings can be fairly long.  When I output the HTML, I would to add a
hint to the browser that it can hyphenate this string at any ".".  So when I output the string I
would like it to be

machine&shy;.site&shy;.domain

So that it can be rendered as 

machine-
.site.domain

or 

machine.site-
.domain

as needed.

I've several versions of a recursive template to replace all occurences of "." with "&shy;.".
However, 
my output string always end up being

machine&amp;shy;.site&amp;shy;.domain

which renders as

machine&shy;.site&shy.domain

I am using the xalan XSLT engine.

I has a working version of this that only replaced the first "." with &shy; that worked fine.  But
that was being done inline and not in a recursive template.

<xsl:template name="SoftHyphenString">
    <xsl:param name="src"/>
    <xsl:param name="dst"/>

     <xsl:choose>
       <xsl:when test="string-length($src) = 0">
          <xsl:value-of select="$dst"/>
       </xsl:when>
       <xsl:otherwise>
          <xsl:call-template name="SoftHyphenString">
             <xsl:with-param name="src">
                 <xsl:value-of select="substring-after($src, '.')"/>
             </xsl:with-param>
             <xsl:with-param name="dst">
               <xsl:choose>
                  <xsl:when test="contains($src, '.')">
                      <xsl:value-of select="concat($dst, substring-before($src, '.'))"/><xsl:text
disable-output-escaping="yes">&amp;shy;.</xsl:text>
                 </xsl:when>
                 <xsl:otherwise>
                     <xsl:value-of select="concat($dst, $src)"/>
                 </xsl:otherwise>
              </xsl:choose>
            </xsl:with-param>
          </xsl:call-template>
         </xsl:otherwise>
     </xsl:choose>
  </xsl:template>




Jim Miller 
_____________________________________
Visualization & Computer Vision
GE Corporate Research & Development
Bldg. KW, Room C218B
P.O. Box 8, Schenectady NY 12301

millerjv@xxxxxxxxxx <mailto:millerjv@xxxxxxxxxx>
(518) 387-4005, Dial Comm: 8*833-4005, 
Cell: (518) 505-7065, Fax: (518) 387-6981 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread