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

Re: Escaping for use in URLs

Subject: Re: Escaping for use in URLs
From: "Steve Muench" <smuench@xxxxxxxxxxxxx>
Date: Fri, 5 May 2000 13:24:30 -0700
xsl param escaping
My post bounced yesterday... Here's a resend...

| and I miss spoke the last time . . . it basically needs to make the value
| URL-encoded . . . meaning
| 
| space  =    %20
| /         =     %2F
| ?        =     %3F
| etc . . . .

You could use a "replace-this-with-that" kind of
named template along the lines of this below. It
takes the string "test / ?" and produces:

<a href="test%20%2F%20%3F"/>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <!-- Example illustrating how to use QuoteURL -->
  <xsl:template match="/">
    <a>
      <xsl:attribute name="href">
        <xsl:call-template name="QuoteURL">
          <xsl:with-param name="text">test / ?</xsl:with-param>
        </xsl:call-template>
      </xsl:attribute>
    </a>
  </xsl:template>

  <xsl:template name="QuoteURL">
    <xsl:param name="text"/>
    <xsl:call-template name="ReplaceThisWithThat">
      <xsl:with-param name="text">
        <xsl:call-template name="ReplaceThisWithThat">
          <xsl:with-param name="text">
            <xsl:call-template name="ReplaceThisWithThat">
              <xsl:with-param name="text">
                <xsl:value-of select="$text"/>
              </xsl:with-param>
              <xsl:with-param name="this" select="'/'"/>
              <xsl:with-param name="that" select="'%2F'"/>
            </xsl:call-template>
          </xsl:with-param>
          <xsl:with-param name="this" select="'?'"/>
          <xsl:with-param name="that" select="'%3F'"/>
        </xsl:call-template>
      </xsl:with-param>
      <xsl:with-param name="this" select="' '"/>
      <xsl:with-param name="that" select="'%20'"/>
    </xsl:call-template>
  </xsl:template>

  <!-- Replace occurrence of this with that  -->
  <xsl:template name="ReplaceThisWithThat">
    <xsl:param name="text"/>
    <xsl:param name="this"/>
    <xsl:param name="that"/>
    <xsl:choose>
    <xsl:when test="contains($text,$this)">
        <xsl:value-of select="substring-before($text,$this)"/>
        <xsl:value-of select="$that"/>
        <xsl:call-template name="ReplaceThisWithThat">
          <xsl:with-param name="text" select="substring-after($text,$this)"/>
          <xsl:with-param name="this" select="$this"/>
          <xsl:with-param name="that" select="$that"/>
        </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$text"/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:template>

</xsl:stylesheet>

______________________________________________________________
Steve Muench, Lead XML Evangelist & Consulting Product Manager
Business Components for Java & XSQL Servlet Development Teams
Oracle Rep to the W3C XSL Working Group


 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.