XSL learning experience-making image hyperlinks

Source: Internet
Author: User
Tags version xmlns xsl
Links | experience

This is another problem that I encountered when I was studying today. Do image hyperlinks to the link address to the <a> href attribute to go, but this is the label in the set of tags, it is not possible, check the "Web Programming Practice Tutorial", just know the correct solution, and now share with you.


This code runs two pictures: A.gif and b.gif.

My.xml
The following are program code:

<?xml version= "1.0" encoding= "GB2312"?>
<?xml-stylesheet type= "text/xsl" href= "mystyle.xsl"?>
<Books>
<book id= "a001" >
<Name> Network Guide </Name>
<Photo>a.gif</Photo>
<Homepage>http://www.a.com</Homepage>
</Book>
<book id= "a002" >
<Name> LAN Technology </Name>
<Photo>b.gif</Photo>
<Homepage>http://www.b.com</Homepage>
</Book>
</Books>


Mystyle.xsl
The following are program code:

<?xml version= "1.0" encoding= "GB2312"?>
<xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" >
<xsl:template match= "Books/book" >
<xsl:element name= "a" >
<xsl:attribute name= "href" >
<xsl:value-of select= "./homepage"/>
</xsl:attribute>
<xsl:element name= "img" >
<xsl:attribute name= "src" >
<xsl:value-of select= "./photo"/>
</xsl:attribute>
</xsl:element>
</xsl:element>
<br/>
</xsl:template>
</xsl:stylesheet>


Display results on browsers:
The vertical equal column displays two pictures.

Description
Using hyperlinks, you need <xsl:element> and <xsl:attribute> two tags, the basic use of the method can refer to the above example, in the esoteric, if you want to come out, remember to share yo.


Long experience, hey, this is really the first time to see.
{Homepage}
<xsl:value-of select= "Homepage"/>
The two are equivalent at all times, right?


Your top code and my original effect a little different, I help you improve it:
Mystyle.xsl
<?xml version= "1.0" encoding= "GB2312"?>
<xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" >
<xsl:template match= "Books/book" >
<a href= "{homepage}" >

</a>
</xsl:template>
</xsl:stylesheet>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.