1

我对 xslt 很陌生,想知道如何根据如下派生变量进行排序(使用 xslt 1.0):

xml:

<channel>
  <item>
     <title>#2: Second Guy</title>
  </item>
  <item>
     <title>#3: Third Guy</title>
  </item>
  <item>
     <title>#1: First Guy</title>
  </item>
</channel>

xslt 尝试:

<xsl:for-each select="channel/item" >

        <xsl:sort select="$rank" data-type="number" order="ascending" />

        <xsl:variable name="rankStartPosn" select="string-length(substring-before(title, '#'))+1"/>
        <xsl:variable name="rankEndPosn" select="string-length(substring-before(title, ':'))+1"/>
        <xsl:variable name="rank" select="substring(title,number($rankStartPosn), number($rankEndPosn)-number($rankStartPosn))"/>

                <p class="Normal">
                    <xsl:value-of select="title" />
                </p>
            </xsl:if>
        </xsl:if>
    </xsl:for-each>

期望的输出:

#1: First Guy
#2: Second Guy
#3: Third Guy

提前感谢您的帮助!乍得

4

2 回答 2

0

啊……顿悟!

只是不要使用变量并将整个表达式放在排序的选择中......比如:

<xsl:sort data-type="number" order="ascending" 
             select="substring(title,number(string-length(substring-before(title, '#'))+2), number(string-length(substring-before(title, ':'))+1)-number(string-length(substring-before(title, '#'))+2))"/>
于 2012-07-06T23:33:36.380 回答
0

更简单

<xsl:sort select="substring(substring-before(title, ':'), 2)" 
          data-type="number" order="ascending" />
于 2012-07-07T04:04:36.180 回答