sort不能与xsl一起使用

sort不能与xsl一起使用

本文介绍了xsl:sort不能与xsl一起使用:choose或if的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个XSL问题感到很疯狂!

Im going crazy on this XSL problem i have!

问题是我想在FORM中选择的内容后对报纸进行排序。如果 $ sort_newspaper ='name'并且它应该在名称后排序(< xsl:sort select =./@ name/> )...但是......如果 xsl:sort 存在于choose或之后,它不起作用。它也不适用于 xsl:if

The thing is that i want to sort newspaper after what is choosen in a FORM. If $sort_newspaper = 'name' and it should sort after name (<xsl:sort select="./@name"/> )... but... it does not work if the xsl:sort exist inside the choose or after. It also does not work with xsl:if.

要清楚它现在就像代码一样工作,选择有效...

To be clear it work like the code are now, the choose works...

    <xsl:for-each select="./newspaper[count(. | key('newspaper_key', ./@id)[1]) = 1]">
            <xsl:sort select="./@name"/>

            <xsl:choose>
                <xsl:when  test="$sort_newspaper = 'name'">
                    XSL:SORT SHOULD BE HERE BUT THAT WILL RESULT IN ERROR!
                </xsl:when>
                <xsl:otherwise>
                    HALLO
                </xsl:otherwise>
            </xsl:choose>
IF XSL:SORT WOULD BE HERE IT WOULD RESULT IN ERROR TOO!
    </xsl:for-each>


推荐答案

抱歉,坏消息。这不行。只有可能的解决方案(我现在看到)将整个 xsl:for-each 放入 xsl:when (有或没有排序)。

Sorry bad news. This will not work. Only possible solution (I see at the moment) would be to put the whole xsl:for-each into the xsl:when (with or without sort).

您的代码示例应如下所示:

Your code example should than look like this:

<xsl:variable name="newspaper_group" select="./newspaper[count(. | key('newspaper_key', ./@id)[1]) = 1]" />
<xsl:choose>
    <xsl:when  test="$sort_newspaper = 'name'">
        <xsl:for-each select="$newspaper_group" >
            <xsl:sort select="./@name"/>
            <!-- Sorted stuff -->
        </xsl:for-each>
    </xsl:when>
    <xsl:otherwise>
        <xsl:for-each select="$newspaper_group" >
            <!-- Unsorted stuff -->
        </xsl:for-each>
    </xsl:otherwise>
</xsl:choose>

这篇关于xsl:sort不能与xsl一起使用:choose或if的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 23:32