【发布时间】:2022-01-02 08:31:45
【问题描述】:
只是我想做简单的连接。当我迭代值时,我只想在一个字符串中获取所有产品名称并打印该值。这是我的 XML:
<CartItems>
<CartItem>
<ProductPrice>605.0000</ProductPrice>
<ProductWeight>2.2975</ProductWeight>
<ProductID>722</ProductID>
<VariantID>235</VariantID>
<Quantity>1</Quantity>
<ProductName>ProductName1</ProductName>
</CartItem>
<CartItem>
<ProductPrice>349.9900</ProductPrice>
<ProductWeight>6.1731</ProductWeight>
<ProductID>070</ProductID>
<VariantID>296</VariantID>
<Quantity>1</Quantity>
<ProductName>ProductName2</ProductName>
</CartItem>
</CartItems>
这是我的代码:
<xsl:template name="CartItemProductNames">
<xsl:param name="Data" />
<xsl:variable name="CombineProductName">
</xsl:variable>
<xsl:for-each select="$Data">
<xsl:if test="position()=1">
-- set value in CombineProductName
</xsl:if>
{
'ProductName':'<xsl:value-of select="ProductName" disable-output-escaping="yes" />',
<xsl:variable name="ProductName" select="ProductName">
<xsl:value-of select="$Total_Amount"/>
</xsl:variable>,
'Combined':'<xsl:value-of select="concat($CombineProductName,', ', $ProductName)" />'
}
</xsl:for-each>
<xsl:value-of select="$CombineProductName" disable-output-escaping="yes" />
</xsl:template>
这个 ackage 被称为:
'$PRODUCTNAMES' ='<xsl:call-template name="CartItemProductNames">
<xsl:with-param name="Data" select="/root/CartItems/CartItem"/>
</xsl:call-template>',
期望的输出:
'$PRODUCTNAMES':'{ProductName1, ProductName2, and more if there will be in list}'
我是 xslt 的新手。请帮我解决这个问题。
【问题讨论】:
-
在所有有关 XSLT 的问题中,请说明您的处理器支持哪个版本的 XSLT。
-
从 XPath 教程开始,然后转到 XSLT 教程。不要指望我们会为你写一篇。
-
@MartinHonnen,我不希望为我编写代码,我已经发布了我尝试过的内容。还有一件事,我们在这里帮助他人。是的,这是有道理的,我是这个的学习者,当然你也曾经有过一段时间
-
@michael.hor257k 我正在使用 XSLT 版本 1.. 刚刚使用 版本是:
得到的版本是:1