Re: [xsl] How do I generate an HTML anchor element?

Subject: Re: [xsl] How do I generate an HTML anchor element?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 28 Oct 2002 14:19:19 +0000
Hi Jim,

> I have checked the FAQ's for mulberrytech, jennitennison, and
> Pawson's without any success. I must not be inputting the search
> criteria correctly.

The XSLT FAQs tend not to go into XML well-formedness problems, which
is what you're experiencing. Remember that XSLT stylesheets must be
well-formed XML documents -- use an XML parser or editor to locate the
syntax errors first (so that, for example, IE will display your
stylesheet as a nice collapsible tree), then start worrying about XSLT

> All I'm trying to do is generate an HTML anchor tag. I all the
> combinations get syntax errors .
> Here is where I originally started:
> <table>
> <tr>
>     <td>
>          <a HREF="SomeURL.jsp?FirstName=FirstValue&SecondValue
> =<xsl:value-of select="AAA/BBB"/>>        <xsl:value-of select="DDD"/>
>          </a>
>     </td>
>    </tr>
> </table>

This isn't well-formed XML because of two things. First, you've got an
unescaped & in there when you shouldn't have. Second, you've got an
<xsl:value-of> element inside an attribute value. Usually when people
try the latter it's because they haven't heard of attribute value
templates -- use {}s in an attribute value to say "insert this value
here". In your case try:

<a HREF="SomeURL.jsp?FirstName=FirstValue&amp;SecondValue={AAA/BBB}">
  <xsl:value-of select="DDD" />

Note the escaped & as well as the attribute value template. A longer
alternative would be to create the HREF attribute using

    <xsl:attribute name="HREF">
      <xsl:value-of select="AAA/BBB" />
    <xsl:value-of select="DDD" />

XSLT isn't like ASP or JSP -- you can't just insert XSLT instructions
wherever you like and have the result inserted textually into the
document. Instead, you're creating a tree of element, attribute and
text nodes (and some others, but those are the main ones). If you keep
that in mind, the solutions are often easier to find.


Jeni Tennison

 XSL-List info and archive:

Current Thread