umbraco 不断返回第一个子节点而不是所有子节点值

发布于 2024-11-26 02:12:11 字数 1557 浏览 1 评论 0原文

我在使用 XSLT 从每个子节点选择和显示子字符串时遇到问题我使用了以下代码我确信我错过了一些非常简单的东西这只是返回第一个子节点 4 次,因为有 4 个子节点。有人可以帮忙吗?

XSLT 代码

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-12-03 02:12:11

我认为你可以完全放弃参数和循环。

<xsl:for-each select="$currentPage/WhatWeDoItems [@isDoc]">
    <xsl:variable name="description" select="whatWeDoItemDescription"/>
    <p><xsl:value-of select="umbraco.library:TruncateString($description,170,'...')"/></p>
</xsl:for-each>

I think you can completely ditch the parameter and the loop.

<xsl:for-each select="$currentPage/WhatWeDoItems [@isDoc]">
    <xsl:variable name="description" select="whatWeDoItemDescription"/>
    <p><xsl:value-of select="umbraco.library:TruncateString($description,170,'...')"/></p>
</xsl:for-each>
旧话新听 2024-12-03 02:12:11

此代码

    <xsl:param name="testString">
        <xsl:for-each select="$currentPage/WhatWeDoItems [@isDoc]">
            <xsl:value-of select="whatWeDoItemDescription"/>
        </xsl:for-each>
    </xsl:param>

定义名为 testStringxsl:param 以包含单个字符串,该字符串是$currentPage/WhatWeDoItems [@isDoc] 的每个(四个)whatWeDoItemDescription 子级的(四个)字符串值。

然后,您输出此连接的截断子字符串四次,并且它仅显示四个连接字符串中第一个的截断。

解决方案

您不应该在参数中连接字符串 - 只需选择所有想要的元素:

<xsl:param name="pTestString" select=
            "$currentPage/WhatWeDoItems[@isDoc]/whatWeDoItemDescription"/>

<xsl:for-each select="$pTestString">
  <p><xsl:value-of select=
    "umbraco.library:TruncateString(.,170,'...')"/></p>
</xsl:for-each>         

This code:

    <xsl:param name="testString">
        <xsl:for-each select="$currentPage/WhatWeDoItems [@isDoc]">
            <xsl:value-of select="whatWeDoItemDescription"/>
        </xsl:for-each>
    </xsl:param>

defines the xsl:param named testString 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:

<xsl:param name="pTestString" select=
            "$currentPage/WhatWeDoItems[@isDoc]/whatWeDoItemDescription"/>

<xsl:for-each select="$pTestString">
  <p><xsl:value-of select=
    "umbraco.library:TruncateString(.,170,'...')"/></p>
</xsl:for-each>         
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文