gpt4 book ai didi

xml - 如何定义 XSL 变量并在 xsl :choose 中赋值

转载 作者:数据小太阳 更新时间:2023-10-29 02:05:30 24 4
gpt4 key购买 nike

我想在 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">&amp;nbsp;</xsl:text>
<xsl:if test="middlename != ''">
<xsl:value-of select="middlename"/><xsl:text disable-output-escaping="yes">&amp;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>

最佳答案

这是 XSL 新手的常见错误。正确的做法是:

<xsl:variable name="category">
<xsl:choose>
<xsl:when test="objecttype='1'">car</xsl:when>
<xsl:when test="objecttype='2'">bus</xsl:when>
... etc
</xsl:choose>
</xsl:variable>

在您的示例中,变量是 <xsl:when...> 的本地变量标签。

关于xml - 如何定义 XSL 变量并在 xsl :choose 中赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7589765/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com