XSLT for-each 循环,基于变量的过滤器
我有以下 XSLT
<xsl:param name="productsId" select="/macro/productsId" />
<xsl:param name="type" select="/macro/type" /> <!-- value1, value2, value3 -->
<xsl:template match="/">
<xsl:if test="$productsId > 0">
<xsl:variable name="products" select="umbraco.library:GetXmlNodeById($productsId)" />
<div id="carousel-wrap">
<ul id="carousel">
<xsl:for-each select="$products/Product [select only Product with attribute value1, value2 or value3 based on /macro/type]">
<li id="p-{@id}">
<xsl:variable name="title">
<xsl:choose>
<xsl:when test="string-length(productHeading) > 0">
<xsl:value-of select="productHeading" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@nodeName" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<a href="{umbraco.library:NiceUrl(@id)}">
<!-- Image -->
<xsl:if test="productImage > 0">
<xsl:variable name="productImage" select="umbraco.library:GetMedia(productImage, 0)" />
<img src="/ImageGen.ashx?image={$productImage/umbracoFile}&height=131" />
</xsl:if>
<!-- Title -->
<span><xsl:value-of select="$title" disable-output-escaping="yes" /></span>
</a>
</li>
</xsl:for-each>
</ul>
</div>
</xsl:if>
</xsl:template>
基本上,每个产品都包含 3 个具有真/假值的属性。
value1 = true
value2 = false
value3 = true
现在我将一个参数传递给样式表,该参数将是这些值之一,即 value3。
我想选择 value3 设置为 true 的所有节点。大致如下:
<xsl:for-each
select="$products/Product [$type = 'true' (or $type = '1' in XSLT terms)]">
关于如何实现这一点有什么想法吗?
I have the following XSLT
<xsl:param name="productsId" select="/macro/productsId" />
<xsl:param name="type" select="/macro/type" /> <!-- value1, value2, value3 -->
<xsl:template match="/">
<xsl:if test="$productsId > 0">
<xsl:variable name="products" select="umbraco.library:GetXmlNodeById($productsId)" />
<div id="carousel-wrap">
<ul id="carousel">
<xsl:for-each select="$products/Product [select only Product with attribute value1, value2 or value3 based on /macro/type]">
<li id="p-{@id}">
<xsl:variable name="title">
<xsl:choose>
<xsl:when test="string-length(productHeading) > 0">
<xsl:value-of select="productHeading" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@nodeName" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<a href="{umbraco.library:NiceUrl(@id)}">
<!-- Image -->
<xsl:if test="productImage > 0">
<xsl:variable name="productImage" select="umbraco.library:GetMedia(productImage, 0)" />
<img src="/ImageGen.ashx?image={$productImage/umbracoFile}&height=131" />
</xsl:if>
<!-- Title -->
<span><xsl:value-of select="$title" disable-output-escaping="yes" /></span>
</a>
</li>
</xsl:for-each>
</ul>
</div>
</xsl:if>
</xsl:template>
Basically, each product contains 3 attributes with true/false values.
value1 = true
value2 = false
value3 = true
Now I'm passing a parameter to my stylesheet which will be one of these values, i.e. value3.
I would like to select all nodes that have value3 set to true. Something along the lines of:
<xsl:for-each
select="$products/Product [$type = 'true' (or $type = '1' in XSLT terms)]">
Any ideas on how this can be accomplished?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您正在寻找这样的东西:
请注意,很少需要使用
for-each
。考虑以下样式表:应用于此输入:
生成:
I believe you're looking for something like this:
Note that use of
for-each
is rarely necessary. Consider the following stylesheet:Applied to this input:
Produces: