This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Making dynamic href's in XSL


> 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,
though:

  &#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
http://freespace.virgin.net/b.pawson/xsl/N7150.html#N11391


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:

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

Although you could also do

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

   - Mike
____________________________________________________________________
Mike J. Brown, software engineer at         My XML/XSL resources:
webb.net in Denver, Colorado, USA           http://www.skew.org/xml/


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]