我正在尝试使用xslt和xml显示图片。当所有其他事情都工作并显示时,不会显示标签“picture”内的photo.xml文件中指定路径的实际图片。
我有一个photo.xml文件,如下所示:
<?xml version="1.0"?>
<pic:photoCatalog xmlns:pic="pictureCatalog">
<pic:photos>
<pic:photo>
<pic:title>Alcazar</pic:title>
<pic:location>Segovia - Spain</pic:location>
<pic:picture> pic
<pic:img src="images/DSC_0183.jpg" orginalwidth="150" />
</pic:picture>
<pic:date>Jan 2013</pic:date>
<pic:camera>Sony</pic:camera>
<pic:resolution>12px</pic:resolution>
<pic:format>.jpg</pic:format>
<pic:description>
Medieval Castle over the hill overlooking the old city of Segovia.
</pic:description>
</pic:photo>
</pic:photos>
</pic:photoCatalog>
然后我有一个index.xml文件,如下所示:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="merge.xsl"?>
<pic:catalog xmlns:pic = "pictureCatalog">
<pic:logo>Logo</pic:logo>
<Author>User Name</Author>
<pic:allPhotos>photos</pic:allPhotos>
</pic:catalog>
最后转型:
<!-- All the photos-->
<xsl:template match = "pic:catalog/pic:allPhotos">
<html>
<head>
<link rel="stylesheet" type="text/css" href="Style.css" />
</head>
<body>
<!--Loop for the sort-->
<xsl:for-each select="document(concat(., '.xml'))/pic:photoCatalog/pic:photos">
<!--point at the fine-->
<xsl:sort select="pic:photo" />
<xsl:value-of select="pic:photo"/><br/>
</xsl:for-each>
</body>
</html>
</xsl:template>
预期输出是包含标签信息的图片列表。正如我所说,一切正常,但没有显示图片。
<div id="CenterAreaTop">
<link rel="stylesheet" type="text/css" href="Style.css">
Acqueduct
Segovia <!--the picture right after this-->
Jan 2013
Olympus
12px
.jpg
2000 Year old aqueduct built by the romans ca. xxxx during the reign of xxx
.....
</div>
有人可以帮忙吗?
谢谢!
答案 0 :(得分:0)
好的,这是怎么回事:
<xsl:template match = "pic:catalog/pic:allPhotos">
<html>
<head>
<link rel="stylesheet" type="text/css" href="Style.css" />
</head>
<body>
<xsl:apply-templates select="document(concat(., '.xml'))/pic:photoCatalog/pic:photos/pic:photo">
<xsl:sort select="pic:title" />
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="pic:photo">
<xsl:apply-templates select="*" />
<br />
</xsl:template>
<xsl:template match="pic:img">
<img src="{@src}" alt="" />
</xsl:template>