umbraco 不断返回第一个子节点而不是所有子节点值
我在使用 XSLT 从每个子节点选择和显示子字符串时遇到问题我使用了以下代码我确信我错过了一些非常简单的东西这只是返回第一个子节点 4 次,因为有 4 个子节点。有人可以帮忙吗?
XSLT 代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:param name="testString">
<xsl:for-each select="$currentPage/WhatWeDoItems [@isDoc]">
<xsl:value-of select="whatWeDoItemDescription"/>
</xsl:for-each>
</xsl:param>
<xsl:for-each select="$currentPage/WhatWeDoItems [@isDoc]">
<p><xsl:value-of select="umbraco.library:TruncateString($testString,170,'...')"/></p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I am having an issue selecting and displaying a substring from each of the child nodes using XSLT I have used the following code I'm sure I'm missing something really simple this just returns the first child node 4 times as there are 4 child nodes. Can anyone help?
XSLT CODE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:param name="testString">
<xsl:for-each select="$currentPage/WhatWeDoItems [@isDoc]">
<xsl:value-of select="whatWeDoItemDescription"/>
</xsl:for-each>
</xsl:param>
<xsl:for-each select="$currentPage/WhatWeDoItems [@isDoc]">
<p><xsl:value-of select="umbraco.library:TruncateString($testString,170,'...')"/></p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你可以完全放弃参数和循环。
I think you can completely ditch the parameter and the loop.
此代码:
定义名为
testString
的xsl:param
以包含单个字符串,该字符串是$currentPage/WhatWeDoItems [@isDoc]
的每个(四个)whatWeDoItemDescription 子级的(四个)字符串值。然后,您输出此连接的截断子字符串四次,并且它仅显示四个连接字符串中第一个的截断。
解决方案:
您不应该在参数中连接字符串 - 只需选择所有想要的元素:
This code:
defines the
xsl:param
namedtestString
to contain a single string, which is the concatenation of the (four) string values of each (of the four)whatWeDoItemDescription
children of$currentPage/WhatWeDoItems [@isDoc]
.Then you output four times a truncated substring of this concatenation and it shows a truncation of just the first of the four concatenated strings.
Soluton:
You shouldn't be concatenating strings in the parameter -- simply select all wanted elements: