0

我有一个 for each 循环新闻项目节点。在其他属性中,这些新闻项目有两个属性用于创建日期。系统添加日期和用户输入的创建日期(以覆盖系统日期)。我希望该列表按创建日期排序,并带有用户输入日期的首选项。

以下是我卑微的无效尝试!

<xsl:for-each select="$currentPage/ancestor-or-self::node /node [@nodeTypeAlias = $documentTypeAlias and string(data [@alias='umbracoNaviHide']) != '1']">

<xsl:choose>
 <xsl:when test="data [@alias = 'createdDate'] != ''">
  <xsl:variable name="sort" select="string(data [@alias = 'createdDate'])"/>
 </xsl:when>
 <xsl:otherwise>
  <xsl:variable name="sort" select="string(@createDate)"/>
 </xsl:otherwise>
</xsl:choose>

<xsl:sort select="$sort" order="descending"/>

非常感谢

4

4 回答 4

7
<xsl:sort select="(data[@alias='createdDate' and normalize-space() != '']|@createDate)[last()]" order="descending" />

该语句创建一个包含日期的两个节点的节点集,并根据文档顺序获取最后一个进行排序。如果数据节点存在且不为空,则将用于排序,因为元素的子元素出现在其属性节点之后。

concat() 只能工作,在少数情况下,如果你使用文本排序;它会因数字排序而失败。

于 2009-11-09T08:30:35.327 回答
0

对,似乎是一个 hack,但我已经能够通过使用带有排序的 concat 来实现这一点。

下面的例子

<xsl:for-each select="$currentPage/ancestor-or-self::node /node [@nodeTypeAlias = $documentTypeAlias and string(data [@alias='umbracoNaviHide']) != '1']">
<xsl:sort select="concat(data [@alias = 'createdDate'],@createDate)" order="descending"/>
于 2009-11-08T19:42:11.257 回答
0

在 XSLT 中测试节点是否为空(或省略):

<xsl:when test="not(string(name))">...</xsl:when>
<!-- or -->
<xsl:when test="not(name)">...</xsl:when>
于 2009-11-08T19:47:06.067 回答
0

非常感谢 Erlock 的解决方案。由于对 Umbraco XSLT 语法所做的更改,我确实为在我的 Umbraco (4.7.1) 版本中工作而苦苦挣扎了一段时间。

对于任何感兴趣的人,我的工作示例会将 Erlock 的代码更改为;

<xsl:sort select="(current()/createdDate[normalize-space() != '']|@createDate)[last()]" order="descending" />
于 2012-01-18T15:00:30.527 回答