XSLT如果first为空,则将排序应用于第二个值

Max*_*Max 0 sorting xslt umbraco

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

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

<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"/>
Run Code Online (Sandbox Code Playgroud)

非常感谢

Erl*_*ock 7

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

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

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