Subject: Re: [xsl] Netscape Navigator not displaying emdash From: Robert Koberg <rob@xxxxxxxxxx> Date: Thu, 21 Dec 2000 15:08:04 -0800 |
Does this do what you need? Here's the xsl template for the generic search-and-replace functionality. Below that is a URL-encoding template that uses a predefined list of search and replace strings and uses the search-and-replace template. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++ generic search and replace +++++++++++++++++ <!-- sample how to use generic search-and-replace: --> <xsl:variable name="string" select="'string to be searched-and-replaced'"/> <xsl:variable name="find" select="'stringfragment-that-has-to-be-replaced'"/> <xsl:variable name="replace" select="'the-replacement-stringfragment'"/> <xsl:call-template name="_replace_string"> <xsl:with-param name="string" select="substring-after($string,$find)"/> <xsl:with-param name="find" select="$find"/> <xsl:with-param name="replace" select="$replace"/> </xsl:call-template> IN STYLESHEET: <!-- template to look for all instances of string $find and replace that with string $replace --> <xsl:template name="_replace_string"> <xsl:param name="string" select="''"/> <xsl:param name="find" select="''"/> <xsl:param name="replace" select="''"/> <xsl:choose> <xsl:when test="contains($string,$find)"> <xsl:value-of select="concat(substring-before($string,$find),$replace)"/> <xsl:call-template name="_replace_string"> <xsl:with-param name="string" select="substring-after($string,$find)"/> <xsl:with-param name="find" select="$find"/> <xsl:with-param name="replace" select="$replace"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$string"/> </xsl:otherwise> </xsl:choose> </xsl:template> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++ URL-ENCODING ++++++++++++++++++++++++ <!-- sample how to use url-encoding template: --> <xsl:call-template name="_url_encode"> <xsl:with-param name="url" select="@url"/> </xsl:call-template> IN STYLESHEET: <!-- select the find-replace strings that are defined in a separate xml document --> <xsl:variable name="url-enc_search" select="document('_lookup.xml')/lookup/url-encoding/search"/> <!-- URL encoding template --> <xsl:template name="_url_encode"> <xsl:param name="url" select="''"/> <xsl:param name="search_element_nr" select="'1'"/> <xsl:variable name="encoded_url"> <xsl:call-template name="_replace_string"> <xsl:with-param name="string" select="$url" /> <xsl:with-param name="find" select="$url-enc_search[$search_element_nr]/@find"/> <xsl:with-param name="replace" select="$url-enc_search[$search_element_nr]/@replace"/> </xsl:call-template> </xsl:variable> <xsl:choose> <xsl:when test="$search_element_nr < count($url-enc_search)"> <xsl:call-template name="_url_encode"> <xsl:with-param name="url" select="$encoded_url" /> <xsl:with-param name="search_element_nr" select="$search_element_nr + 1" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$encoded_url"/> </xsl:otherwise> </xsl:choose> </xsl:template> ================================================= FILE _LOOKUP.XML FOR URL-ENCODING: <?xml version="1.0" encoding="UTF-8"?> <lookup> <url-encoding> <search find="~" replace="%7E"/> <search find="?" replace="%3F"/> <search find="&" replace="%26"/> <search find="#" replace="%23"/> <search find=":" replace="%3A"/> <search find="=" replace="%3D"/> <search find="@" replace="%40"/> <search find=" " replace="%20"/> <search find="," replace="%2C"/> <search find="/" replace="%2F"/> <search find="\" replace="%5C"/> </url-encoding> </lookup> ----- Original Message ----- From: "Eric van der Vlist" <vdv@xxxxxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Wednesday, December 20, 2000 2:00 AM Subject: Re: [xsl] Netscape Navigator not displaying emdash > Dylan Walsh wrote: > > > > I have a different suggestion from the others: Use the XML output mode in > > your stylesheet. Seen as > > the HTML output mode is the one that replaces — with —, this > > should not happen in XML mode. > > > > You'll be generating a sort of XHTML (really it is just well-formed HTML). > > There are some compatibility tricks on the W3C site for older browsers e.g. > > putting a space in empty tags e.g. "<br />" instead of "<br/>". > > Sure, but there are no standard ways to control that either from XSLT :) > ... > > Eric > -- > ------------------------------------------------------------------------ > Eric van der Vlist Dyomedea http://dyomedea.com > http://xmlfr.org http://4xt.org http://ducotede.com > ------------------------------------------------------------------------ > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Netscape Navigator not di, Eric van der Vlist | Thread | [xsl] accessing token in data..., Martin Giroux |
RE: [xsl] XPATH: Can not convert #S, Weakliem, Gordon | Date | Re: [xsl] XPATH: Can not convert #S, Steve Muench |
Month |