我有一个对每个其循环轮新闻项节点。在其它性质,这些新闻条目有创建日期两个属性。系统添加日期和用户输入的创建日期(覆盖系统日期)。我想通过创建日期与所述用户输入的日期的优先排序的列表中。

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

<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"/>

非常感谢

有帮助吗?

解决方案

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

此语句创建与含有日期的两个节点的节点集,并获得根据文档顺序来进行排序的最后一个。如果数据节点存在和不为空,这将被用于分选,因为元素的子元素的属性节点之后发生。

CONCAT()只能工作,在少数情况下,如果使用文本排序;它将失败,数字排序。

其他提示

右键,似乎是一个黑客,但我已经能够通过使用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"/>

要测试一个节点是空的(或省略)在XSLT:

<xsl:when test="not(string(name))">...</xsl:when>
<!-- or -->
<xsl:when test="not(name)">...</xsl:when>

非常感谢Erlock他的解决方案。我没有奋斗一段时间才能得到我的版本一把umbraco(4.7.1)的这个工作由于对一把umbraco XSLT语法所做的更改。

对于有兴趣的人,我的工作样本将改变Erlock的代码变成;

<xsl:sort select="(current()/createdDate[normalize-space() != '']|@createDate)[last()]" order="descending" />
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top