문제

라운드 뉴스 항목 노드를 루프하는 각각에 대해 있습니다. 다른 속성 중에서이 뉴스 항목에는 생성 날짜에 대한 두 가지 속성이 있습니다. 시스템이 추가 된 날짜와 사용자가 생성 날짜를 입력했습니다 (시스템 날짜를 무시하기 위해). 사용자 입력 날짜에 선호도가있는 생성 날짜별로 목록을 정렬하고 싶습니다.

아래는 저의 겸손한 유효하지 않은 시도입니다!

<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 ()는 텍스트 정렬을 사용하는 경우에만 작동 할 수 있으며 몇 가지 경우에만 작동 할 수 있습니다. 숫자 정렬로 실패합니다.

다른 팁

맞아, 해킹처럼 보이지만 나는 그 종류와의 동의를 사용하여 이것을 달성 할 수 있었다.

아래의 예

<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 XSLT 구문에 대한 변경으로 인해 Umbraco (4.7.1) 버전 에서이 작업을 수행하기 위해 한동안 어려움을 겪었습니다.

관심있는 사람이라면 누구나 작업 샘플이 Erlock의 코드를 변경하여 변경할 것입니다.

<xsl:sort select="(current()/createdDate[normalize-space() != '']|@createDate)[last()]" order="descending" />
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top