此段代码运转须要两张图片:a.gif和b.gif。
my.xml
以下内容为程序代码:
<?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
以下内容为程序代码:
<?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>
在浏览器上的显现结果:
竖向平列显现两个图片。
申明:
运用超链接,须要借助<xsl:element>和<xsl:attribute>两个标签,基础运用方法就能够参照上边的例子,在深邃一点的,假如你想出来了,记得要和人人分享哟。
长见识,嘿嘿,这个但是真是第一次瞥见。
{Homepage}
<xsl:value-of select="Homepage"/>
两个在任何时刻都是等价的吧?
你上边的代码和我本来的结果有点小差异,我帮你完美一下:
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>
以上就是xml图象超链接的制造代码的细致内容,更多请关注ki4网别的相干文章!