How can I include the attribute?

Z

Zhou Lei

Hello now I'm writing the XSL to transform the XML to an html file, and some
xml elements are:

<user login="loginname">
<name>James Cook</name>
</user>

I need to include the login attribute value in my target HTML file, and
concatenate the value with @my.addr.com. So my target HTML code will be

<a href="mailto:[email protected]">
James Cook
</a>

Anyone can give me some suggestions on it, thank you.
 
J

Joris Gillis

Tempore 18:24:34 said:
<user login="loginname">
<name>James Cook</name>
</user>

I need to include the login attribute value in my target HTML file, and
concatenate the value with @my.addr.com. So my target HTML code will be

<a href="mailto:[email protected]">
James Cook
</a>

You can use:
a) an attribute value template:
<xsl:template match="user">
<a href="mailto:{@login}@my.addr.com">
<xsl:apply-templates/>
</a>
</xsl:template>

or b)explicit attribute node creation:
<xsl:template match="user">
<a>
<xsl:attribute name="href">
<xsl:text>mailto:</xsl:text>
<xsl:apply-templates select="@login"/>
<xsl:text>@my.addr.com</xsl:text>
</xsl:attribute>
<xsl:apply-templates/>
</a>
</xsl:template>



regards,
 
M

Martin Honnen

Zhou said:
Hello now I'm writing the XSL to transform the XML to an html file, and some
xml elements are:

<user login="loginname">
<name>James Cook</name>
</user>

I need to include the login attribute value in my target HTML file, and
concatenate the value with @my.addr.com. So my target HTML code will be

<a href="mailto:[email protected]">
James Cook
</a>

<xsl:template match="user">
<a href="mailto:{concat(@login, '@example.com')}">
<xsl:value-of select="name" />
</a>
</xsl:template>
 
Z

Zhou Lei

Joris Gillis said:
Tempore 18:24:34, die Monday 28 February 2005 AD, hinc in foro
{comp.text.xml} scripsit Zhou Lei said:
You can use:
a) an attribute value template:
<xsl:template match="user">
<a href="mailto:{@login}@my.addr.com">
<xsl:apply-templates/>
</a>
</xsl:template>

or b)explicit attribute node creation:
<xsl:template match="user">
<a>
<xsl:attribute name="href">
<xsl:text>mailto:</xsl:text>
<xsl:apply-templates select="@login"/>
<xsl:text>@my.addr.com</xsl:text>
</xsl:attribute>
<xsl:apply-templates/>
</a>
</xsl:template>



regards,

Thank you and Martin very much it works! :)
 

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
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top