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

Re: & in attribute value template

Subject: Re: & in attribute value template
From: Mike Brown <mike@xxxxxxxx>
Date: Sat, 19 Oct 2002 01:34:32 -0600 (MDT)
xslt amp
Guy McArthur wrote:
> Let's say I create an element like this:
> 
> <a href="{@href}">...</a>
> 
> And the value of href is something like "http://host?q=a&amp;u=v".

The href value is actually "http://host/?q=a&u=v" (assuming you meant to put
the slash after the host)... In the serialized document, pre-parsing, it has
"&amp;", but as far as the XSLT processor is concerned, string(@href) has "&"
in it.
 
> Well, the actual output is <a href="http://host?q=a&u=v">...</a> which 
> does not validate.

No processor outputting XML or HTML should do that. When using <xsl:output
method="html"/> or <xsl:output method="xml"/>, it's supposed to escape the "&"
when it outputs the attribute value.

> The solution is to write ampersands in the URL as &amp;amp;

Yowch. Your XSLT processor is broken. In any other processor, you'd get
"&amp;amp;" in your output if you did that.

What XSLT processor are you using, exactly?

And if you can't upgrade it to one that's conformant, I'd see about wrapping
it with something like

<a>
  <xsl:attribute name="href">
    <xsl:choose>
      <xsl:when test="system-property('xsl:vendor')='Crappy XSLT Makers'">
        <!-- see http://skew.org/xml/stylesheets/replace/ for 'replace' template -->
        <xsl:call-template name="replace">
          <xsl:with-param name="stringIn" select="@href"/>
          <xsl:with-param name="substringIn" select="'&amp;'"/>
          <xsl:with-param name="substringOut" select="'&amp;amp;'"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="@href"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:attribute>
</a>

lest it come back to haunt you.

   - Mike
____________________________________________________________________________
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  resume: http://skew.org/~mike/resume/

 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.