This is another problem I encountered when I was studying today. When making images hyperlink, I need to put the link address in the hrefattribute of , but This means that it is not possible to put tags in tags. I checked the "WebProgramming Practical Tutorial" and found out the correct solution. Now I will share it with you.
This code requires two pictures to run: a.gif and b.gif.
my.xml
The following
This is another problem I encountered when I was studying today. To make an image hyperlink, you need to put the link address in the href attribute of , but this is to put a label within a label, right? Yes, I checked the "Web Programming Practical Tutorial" and found out the correct solution. Now I will share it with you.
This code requires two images to run: a.gif and b.gif.
my.xml
The following content is the program code:
<?xml version="1.0" encoding="GB2312"?> <?xml-stylesheet type="text/xsl" href="mystyle.xsl"?> <Books> <Book ID="a001"> <Name>网络指南</Name> <Photo>a.gif</Photo> <Homepage>http://www.a.com</Homepage> </Book> <Book ID="a002"> <Name>局域网技术</Name> <Photo>b.gif</Photo> <Homepage>http://www.b.com</Homepage> </Book> </Books>
mystyle.xsl
The following content is the 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>
The display result on the browser:
Display two pictures vertically in parallel.
Instructions:
To use hyperlinks, you need to use the two tags of
Great experience, hey, this is really the first time I’ve seen this.
{Homepage} <xsl:value-of select="Homepage"/>
Both are equivalent at any time, right?
There is a slight difference between your code above and my original effect. Let me 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}"> <img src="{Photo}"/> </a> </xsl:template> </xsl:stylesheet>
The above is the detailed content of XML code example for making image hyperlinks. For more information, please follow other related articles on the PHP Chinese website!