已经玩了一段时间了.我有一个包含以下行的xml文件
<image size="small">image_small.jpg</image>
<image size="medium">image_medium.jpg</image>
<image size="large">image_large.jpg</image>例如,ANy关于如何才能获得中等url的想法。
目前我有...但这并没有起到作用
<tr>
<td><img><xsl:attribute name="src">
<xsl:value-of select="image/@size[@size=medium]" />
</xsl:attribute>
</img>
</td>
</tr>提前感谢
发布于 2010-12-17 07:57:53
您的问题定义得不是很好,因为我们既没有您的整个XSLT,也没有您想要的输出,但我将尝试一下:
如果使用for循环遍历不同的图像,则需要对循环本身设置约束,而不是对循环的内容设置约束。
如果您将示例代码放在xsl:for-each中,它将遍历每个图像,但仅当带有@size="medium"的image是当前节点时才填充@src属性。这将为您提供三个表行和三个图像,但只有一个图像具有有效的@src属性。
相反,将您的xsl:for-each (or use xsl:apply-templates)更改为仅使用@size="medium"遍历图像
<!-- This will only iterate over the medium sized images. -->
<xsl:for-each select="image[@size='medium']">
<tr>
<td>
<img src="{.}"/>
</td>
</tr>
</xsl:for-each>另一个技巧:使用而不是xsl:attribute,使用attribute value template。
https://stackoverflow.com/questions/4466402
复制相似问题