Home >Backend Development >XML/RSS Tutorial >XML code example for making image hyperlinks

XML code example for making image hyperlinks

黄舟
黄舟Original
2017-03-16 16:39:061559browse

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 and .
Basically use the method to refer to the above example. In a more profound way, Yes, if you come up with it, remember to share it with everyone.
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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn