开发者

umbraco keeps returning the first child node not all childe node values

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 "&#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 na开发者_StackOverflow社区me="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 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>


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>         
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜