Embedding xlst element into html tag

Vital Lobachevsky

Usenet Archive
Joined
May 8, 2004
Messages
1
Reaction score
0
Hi!

I'm absolutely newbie with XSLT. Please, help me with this example.

I have simple XML document like this:

<skip />
<aaa>
<link url="url1" />
<link url="url2" />
<skip />
</aaa>
<skip />

that should be transformed to HTML like:

...
<a href="url1">url1</a>
<a href="url2">url2</a>
...

I suppose, it may looks like this:

<skip />
</xsl:template match="aaa">
<xsl:for-each select="link">
<a href="???"><xsl:value-of select="./@url" /></a>
</xsl:for-each>
</xsl:template>
<skip />

with "./@url" value in place of "???". But I can't use XPath inside html tags. How can I embed xlst element into html tag? If it's impossible, how to implement this transformation?

TIA,
Vital Lobachevsky
 

Patrick TJ McPhee

Usenet Archive
Joined
Apr 2, 2000
Messages
269
Reaction score
0
% </xsl:template match="aaa">
% <xsl:for-each select="link">
% <a href="???"><xsl:value-of select="./@url" /></a> % </xsl:for-each> % </xsl:template> % % with "./@url" value in place of "???". But I can't use XPath inside % html tags. How can I embed xlst element into html tag? If it's % impossible, how to implement this transformation?

You can, using an attribute value template:

</xsl:template match="aaa">
<xsl:for-each select="link">
<a href="{@url}"><xsl:value-of select="./@url" /></a>
</xsl:for-each>
</xsl:template>

You can also use xsl:attribute:

</xsl:template match="aaa">
<xsl:for-each select="link">
<a>
<xsl:attribute name='href'><xsl:value-of select='@url'/></xsl:attribute> <xsl:value-of select="./@url" /></a> </xsl:for-each> </xsl:template>
 

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
548,208
Messages
3,104,798
Members
249,594
Latest member
henrywalsh

Latest Threads

Top