[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: & in attribute value template
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&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 "&", 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; Yowch. Your XSLT processor is broken. In any other processor, you'd get "&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="'&'"/> <xsl:with-param name="substringOut" select="'&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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|