creating a link in XSLT

P

petermichaux

Hi,

I have an XML document that I am transforming with XSLT. The XML is
like this

<departments>
<department>
<name>Dept1</name>
<uri>http://www.domain.com/index.php?dept=1</uri>
</department>
<department>
<name>Dept2</name>
<uri>http://www.domain.com/index.php?dept=2</uri>
</department>
</departments>

and in the XSLT department template I am trying to create unordered
list elements of links to these departments. But the following does not
work

<xsl:template match="department">
<li><a href="<xsl:value-of select="uri"/>"><xsl:value-of
select="name"/></a></li>
</xsl:template>

I get an error

TEXT: /Users/peter/store/xsl/departments.xsl:5: parser error :
Unescaped '<' not allowed in attributes values

How do I write this department template properly?

Thanks!
Peter
 
J

Janwillem Borleffs

I get an error

TEXT: /Users/peter/store/xsl/departments.xsl:5: parser error :
Unescaped '<' not allowed in attributes values

How do I write this department template properly?

<xsl:template match="department">
<li>
<a href="{uri}">
<xsl:value-of select="name" />
</a>
</li>
</xsl:template>


JW
 
P

petermichaux

Thanks for the quick reply! Seems strange to have two methods for
getting an element from and xml document. I'll have to read some
documentation on this.

Peter
 
D

David Carlisle

Thanks for the quick reply! Seems strange to have two methods for
getting an element from and xml document. I'll have to read some
documentation on this.

Peter

an XSLT stylesheet has to be well formed XML, you can't have an element
start tag in an xml attribute so the syntax that you suggested would be
rejected by the xml parser before xslt starts.

David
 
R

reclusive monkey

I tried various methods to get this but eventually found one which I
liked;

<a><xsl:attribute name="href"><xsl:value-of select="link"
/></xsl:attribute><xsl:value-of select="Link Text" /></a>

and of course you switch href for name if you need document anchors,
simply add # before <xsl:value-of select="link" />.
 
D

David Carlisle

<a><xsl:attribute name="href"><xsl:value-of select="link"
/></xsl:attribute><xsl:value-of select="Link Text" /></a>

Most people prefer the less verbose avt syntax


<a href="{link}"><xsl:value-of select="Link Text" /></a>

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,249
Members
46,845
Latest member
GygaKnight

Latest Threads

Top