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> "target=_blank>http://www.a.com </Book> <book id= "a002" > <Name> LAN Technology </Name> <Photo>b.gif</Photo> <Homepage> "target=_blank>http://www.b.com </Book> </Books> |
Mystyle.xsl
The following are program code:
<?xml version= "1.0" encoding= "GB2312"?> <xsl:stylesheet version= "1.0" xmlns:xsl= "target=_blank>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= "target=_blank>http://www.w3.org/1999/XSL/Transform" > <xsl:template match= "Books/book" > <a href= "{homepage}" >
</a> </xsl:template> </xsl:stylesheet> |