xsl-list
[Top] [All Lists]

Re: xslt replace special characters

2002-11-11 12:36:25
Thanks Greg. Right in the UI, we want the user to enter their URL. Their URL will most likely have name/value pairs. Is there an easier way? There is no otherway of filtering '&' before it gets processed in the XSL?

Alice


From: Greg Faron <gfaron(_at_)integretechpub(_dot_)com>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] xslt replace special characters
Date: Mon, 11 Nov 2002 11:48:11 -0700

Alice,

It sounds like your user interface is one where the user types in an URL string. You could offer additional fields if they need to enter multiple name/value pairs (the only reason for an ampersand to appear in an URL). Then your xsl could construct the final URL, adding the '?' if any name/value pairs exist, and then outputting them with your own '&amp;' and '=' characters placed between them.

Sample XML (constructed from text fields):
<userURL>
  <baseURL>http://www.someplace.com/dir/page.htm</baseURL>
  <pair>
    <name>arg1</name>
    <value>value1</value>
  </pair>
  <pair>
    <name>arg2</name>
    <value>value2</value>
  </pair>
  <pair>
    <name>arg3</name>
    <value>value3</value>
  </pair>
</userURL>

Relevant XSL:
<xsl:template match="userURL">
  <xsl:value-of select="baseURL"/>
  <xsl:apply-templates select="pair"/>
</xsl:template>
<xsl:template match="pair">
  <xsl:if test="position() = 1">
    <xsl:text>?</xsl:text>
  </xsl:if>
  <xsl:value-of select="name" />
  <xsl:text>=</xsl:text>
  <xsl:value-of select="value" />
  <xsl:if test="position() != last()">
    <xsl:text>&amp;</xsl:text>
  </xsl:if>
</xsl:template>

Greg

At 08:20 PM 11/10/2002, you wrote:
so the user has to input &amp; or &3038; if their url consisys of an '&'.



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


..........................................................
Email: arisuu(_at_)hotmail(_dot_)com
Cell: (650) 483-8164
Work: (212) 201-0881
..........................................................

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail


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