0

ニュースアイテムノードをループするforeachがあります。他のプロパティの中でも、これらのニュースアイテムには作成日に関する2つの属性があります。システムの追加日とユーザーが作成日を入力しました(システムの日付を上書きするため)。ユーザーが入力した日付を優先して、作成日でリストを並べ替えてください。

以下は私の謙虚な無効な試みです!

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

このステートメントは、日付を含む 2 つのノードを持つノードセットを作成し、ドキュメントの順序に従って最後のノードを取得して並べ替えを行います。データノードが存在し、空でない場合は、要素の子要素がその属性ノードの後に​​発生するため、並べ替えに使用されます。

concat() は、テキストの並べ替えを使用する場合にのみ機能します。数値ソートでは失敗します。

于 2009-11-09T08:30:35.327 に答える
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 に答える
0

そうです、ハックのように思えますが、並べ替えで連結を使用することでこれを達成できました。

以下の例

<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 に答える