当我运行以下代码时...
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="images">
<ul id="tiles">
<xsl:for-each select="entry">
<li>
<xsl:if test="position() mod 4 = 0">
<xsl:attribute name="class">fourth</xsl:attribute>
</xsl:if>
<xsl:choose>
<xsl:when test="datei/meta/@width > datei/meta/@height">
<xsl:variable name="width">600</xsl:variable>
<xsl:variable name="height">450</xsl:variable>
</xsl:when>
<xsl:when test="datei/meta/@width < datei/meta/@height">
<xsl:variable name="width">600</xsl:variable>
<xsl:variable name="height">800</xsl:variable>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="width">600</xsl:variable>
<xsl:variable name="height">600</xsl:variable>
</xsl:otherwise>
</xsl:choose>
<a href="{$root}/image/2/{$width}/{$height}/5{datei/@path}/{datei/filename}" class="fresco" data-fresco-caption="{titel}" data-fresco-group="event">
<img src="{$root}/image/2/320/320/5{datei/@path}/{datei/filename}"/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
我收到一个错误:
XSLTProcessor::transformToXml():
Variable 'width' has not been declared.
xmlXPathCompiledEval: evaluation failed
Variable 'height' has not been declared.
xmlXPathCompiledEval: evaluation failed
这怎么可能?
难道我声明变量width
,并height
在一个错误的方式?
谢谢你的帮助。
有时,我有时更喜欢使用模板规则:
<xsl:variable name="width">
<xsl:apply-templates select="datei/meta/@width" mode="width"/>
</xsl:variable>
<xsl:template match="@width[. > ../@height]" mode="width">600</xsl:template>
<xsl:template match="@width[. < ../@height]" mode="width">600</xsl:template>
<xsl:template match="@width" mode="width">600</xsl:template>
等等。
模板规则是XSLT使用最多的部分。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句