Embedding xlst element into html tag

  • Thread starter Vital Lobachevsky
  • Start date
V

Vital Lobachevsky

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
 
P

Patrick TJ McPhee

% </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

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top