我想在XSL中定义一个名为'category'的变量,给它赋值,并在代码的下方重复使用该变量。
如果objecttype=1,变量值应为“car”
如果objecttype=2,变量值应为“bus”
我该如何实现这一点?
<xsl:template match="/">
<html>
<head><style type="text/css">body{font-size:11px;font-family:Verdana;}</style></head>
<body>
Dear
<xsl:for-each select="user">
<xsl:value-of select="firstname"/><xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
<xsl:if test="middlename != ''">
<xsl:value-of select="middlename"/><xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:value-of select="user/lastname"/>,<br/>
<br/>
You have created a company listing for "<xsl:value-of select="user/objecttitle"/>".<br/>
<br/>
Did you know Google uses the number of Facebook 'likes' for webpages in its rankings?<br/>
You can like you page here:
<xsl:for-each select="user">
<xsl:variable name="category">
<xsl:choose>
<xsl:when test="objecttype='1'">car</xsl:when>
<xsl:when test="objecttype='2'">bus</xsl:when>
</xsl:choose>
</xsl:variable>
</xsl:for-each>
<a href="http://www.mydomain.com/{$category}/{user/objectid}/{user/objecturl}">Click here to go to your company listing now.</a><br/>
Kind regards,<br/>
<br/>
<br/>
</body>
</html>
</xsl:template>
for-each
内定义了变量,因此它在for-each
块之外不存在。我不确定您想要实现什么...链接是否应该在for-each
内部?如果不是,您是否打算使用单个链接来显示最后一个用户的类别?这就是代码当前的意思。 - Jim Garrison