Re: Making dynamic href's in XSL

Subject: Re: Making dynamic href's in XSL
From: Mike Brown <mike@xxxxxxxx>
Date: Wed, 31 May 2000 16:57:39 -0600 (MDT)
> I'm trying to build a dynamic href like this:
> <xsl:if test="num_active_tasks>0"><a
> href="show_tasks.jsp?pcode=<xsl:value-of select="site_code"
> />&#0026;project_number=<xsl:value-of select="number" />"><xsl:value-of
> select="number" /></a>
> but I get the error "The value of attribute "href" must not contain the
> '<' character. ". I understand what the error means, but I'm not sure
> how to get around it. Is there a better way of building a dynamic href?

Regarding the &#0026;, 26 dec = 1A hex = the "SUBSTITUTE" C0 control
character, which is not allowed in an XML document. &#x26; (hex 26 = 38
decimal) is what you meant, for ampersand. Just use &amp;. I'm going to
guess, though, that you tried doing that and didn't like the fact that
you saw '&amp;' in the output. It's not a direct cause-and-effect,

  &#38; or &#x26; or &amp; in XML doc becomes & in stylesheet tree;
  & in stylesheet tree is copied to the result tree; and finally
  & in result tree is output via the XML or HTML output method as &amp;.

The thing is, unless you are writing for a broken HTML user agent, you
*want* &amp; in the output. This is a FAQ; see also

Regarding constructing an attribute, literal result elements are a
shortcut to using <xsl:element> and <xsl:attribute> instructions.
Sometimes it's easier to use the instructions:

  <xsl:attribute name="href">
    <xsl:value-of select="concat('show_tasks.jsp?pcode=',site_code,'&amp;project_number=',number)" />
  <xsl:value-of select="number"/>

Although you could also do

<a href="{concat(blahblahblah)}">
  <xsl:value-of select="number"/>

   - Mike
Mike J. Brown, software engineer at         My XML/XSL resources: in Denver, Colorado, USA 

 XSL-List info and archive:

Current Thread