检查 xslt 中是否存在图像
我的任务是检查图像是否存在并显示它。上层节点是酒店。
Xml 文件:
<PhotoList>
<Photo>
<Url>https://image.shutterstock.com/image-photo/hotel-word-golden-letters-
on-600w-378101848.jpg</Url>
</Photo>
<Photo>
<Url>http://demotest.itravelsoftware.com/fotografije_itravel/7/715_636077306767263022.jpg</Url>
</Photo>
<Photo>
<Url>http://demotest.itravelsoftware.com/fotografije_itravel/7/714_636077303419440444.jpg</Url>
</Photo>
<Photo>
<Url>http://demotest.itravelsoftware.com/fotografije_itravel/7/539_636064349608545756.jpg</Url>
</Photo>
</PhotoList>
Xslt:
<xsl:for-each select="PhotoList/Photo">
<xsl:choose>
<xsl:when test="Photo != ''">
<td><img src="Photo" height="100" width="100"/></td>
</xsl:when>
</xsl:choose>
</xsl:for-each>
这不显示图片,我不确定 != '' 是否可以正确检查 img 是否存在。
My task is to check if image exist and display it. Upper node is Hotel.
Xml file:
<PhotoList>
<Photo>
<Url>https://image.shutterstock.com/image-photo/hotel-word-golden-letters-
on-600w-378101848.jpg</Url>
</Photo>
<Photo>
<Url>http://demotest.itravelsoftware.com/fotografije_itravel/7/715_636077306767263022.jpg</Url>
</Photo>
<Photo>
<Url>http://demotest.itravelsoftware.com/fotografije_itravel/7/714_636077303419440444.jpg</Url>
</Photo>
<Photo>
<Url>http://demotest.itravelsoftware.com/fotografije_itravel/7/539_636064349608545756.jpg</Url>
</Photo>
</PhotoList>
Xslt:
<xsl:for-each select="PhotoList/Photo">
<xsl:choose>
<xsl:when test="Photo != ''">
<td><img src="Photo" height="100" width="100"/></td>
</xsl:when>
</xsl:choose>
</xsl:for-each>
This doesn't display picture and i'm not sure if != '' could properly check if img does or doesn't exists.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您正在寻找的代码是
但只有在存在带有空
Url
子项的Photo
元素时它才有用。函数normalize-space(Url)
确保仅包含空白内容的Url
元素被处理为空。Maybe the code you are looking for is
But it's only useful if there exist
Photo
elements with an emptyUrl
child. The functionnormalize-space(Url)
assures thatUrl
elements with only whitespace content are handled as empty.