我有一个模板,它获取图像,然后将它们输出到两个模板之一。
我希望它根据每个图像的值跟踪每个单独的图像和输出。目前,如果一张图像是宽的,它会根据宽模板将它们全部输出。我宁愿同时使用这两个模板。
<xsl:template name="get-images">
<xsl:param name="image-entry"/>
<xsl:choose>
<xsl:when test="($image-entry/image/meta/@width) > ($image-entry/image/meta/@height)">
<xsl:apply-templates select="$image-entry/image" mode="wide">
<xsl:with-param name="image-class" select="'full-width'"/>
<xsl:with-param name="caption-class" select="'full-width-caption'"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$image-entry/image" mode="tall">
<xsl:with-param name="image-class" select="'center'"/>
<xsl:with-param name="caption-class" select="'full-width-caption'"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="image" mode="wide">
<xsl:param name="image-class" />
<xsl:param name="caption-class" />
<a href="{$root}/image/full{@path}/{filename}">
<img src="{$root}/image/wide{@path}/{filename}" alt="{../description}" class="{$image-class}"/>
</a>
<p class="{$caption-class}">
Image courtesy of: <a href="{../source}"><xsl:value-of select="../title"/></a>
</p>
</xsl:template>
<xsl:template match="image" mode="tall">
<xsl:param name="image-class" />
<xsl:param name="caption-class" />
<span class="centered">
<a href="{$root}/image/full{@path}/{filename}">
<img src="{$root}/image/tall{@path}/{filename}" alt="{../description}" class="{$image-class}"/>
</a>
</span>
<p class="{$caption-class}">
Image courtesy of: <a href="{../source}"><xsl:value-of select="../title"/></a>
</p>
</xsl:template>
额外问题:如果值源不存在,我如何忽略标题?
<article-images field-id="24" subsection-id="5" items="1">
<item id="109" creation-date="2014-04-24T05:16:52+01:00">
<image size="317 KB" path="/uploads" type="image/jpeg">
<filename>funny-lolcat.jpg</filename>
<meta creation="2014-04-24T05:16:52+01:00" width="1600" height="1200" />
</image>
<description mode="formatted"><p>Aww!</p>
</description>
<title handle="" />
<source handle="" />
</item>
</article-images>