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

Re: encoding $ character for wml output via xsl:value-of

Subject: Re: encoding $ character for wml output via xsl:value-of
From: Stephen Zisk <szisk@xxxxxxxxxxxxxxx>
Date: Fri, 01 Sep 2000 15:23:36 -0400
xsl value of encoding

WML syntax uses the $ (dollar sign) for de-referencing a variable.  To
display the character, $$ must be specified, otherwise most WML browsers
return an error.  If an xml file containing a $ in a node is transformed via
XSL (using the xsl:value-of statement) to produce WML, the $ is output as a
$.  Other characters such as &, <, " are output in the encoded form.  Does a
special encoding scheme exist to force the output of a $ in encoded format?
Does some other mechanism exist to allow character transformations to be
customized within an xsl:value-of operation?  Pre-processing the xml file is
an issue as the vast majority of xml inputs do not contain a $.  Post
processing the transformed output is also an issue as the output does
contain WML variable references using the $.

This has been answered before, and perhaps should be in the FAQ.


One simple way, using the XPath string operators, is to call a template that finds the first '$' in a string, replaces it with '$$', and recurses on itself with the remainder of the string:

First, for each string that might contain '$', call the "dollar" template within your XSL to fix it:

<block>
  <xsl:call-template name="dollar">
    <xsl:with-param name="text" select="ELEMENT_TO_FIX" />
  </xsl:call-template>
</block>

Substitute whatever you want checked for the select above. This call to dollar must appear wherever you want the text to be searched.

Next, add a "dollar" template (as called above) into the XSL file, which does a recursive search for '$', replacing it with '$$':

<xsl:template match="text()" name="dollar">
  <xsl:param name="text" select="."/>
  <xsl:choose>
    <xsl:when test="contains($text,'$')">
      <xsl:value-of select="substring-before($text,'$')"/>
      <xsl:text>$$</xsl:text>
      <xsl:call-template name="dollar">
        <xsl:with-param name="text" select="substring-after($text,'$')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$text"/>
   </xsl:otherwise>
   </xsl:choose>
</xsl:template>

Regards,
Stephen Zisk


---------- Stephen Zisk MediaBridge Technologies email: szisk@xxxxxxxxxxxxxxx 100 Nagog Park tel: 978-795-7040 Acton, MA 01720 USA fax: 978-795-7100 http://www.mediabridge.net


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.