[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

string replace with ­

Subject: string replace with ­
From: "Miller, James V (CRD)" <millerjv@xxxxxxxxxx>
Date: Fri, 2 Nov 2001 10:42:49 -0500
shy
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

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