gpt4 book ai didi

sorting - XSL 中的条件排序

转载 作者:行者123 更新时间:2023-12-02 22:00:35 25 4
gpt4 key购买 nike

我有一个使用 XSLT 1.0 转换为 HTML 的 XML 文件,但我想根据用户的选择对数据进行排序。我在 PHP 中为选择设置了一个变量,它可以工作,但我不知道如何进行这种条件排序。

这里是我的带有变量 $sort_by 的代码:

        <xsl:for-each select="gpx:gpx/gpx:wpt">
<xsl:choose>
<xsl:when test="$sort_by = 'name'">
<xsl:sort select="grdspk:cache/grdspk:name"/>
</xsl:when>
<xsl:when test="$sort_by = 'owner'">
<xsl:sort select="grdspk:cache/grdspk:owner"/>
</xsl:when>
<xsl:when test="$sort_by = 'difficulty'">
<xsl:sort select="grdspk:cache/grdspk:difficulty"/>
</xsl:when>
</xsl:choose>

这段代码不起作用,我有一个编译错误“元素排序在该上下文中是不允许的”。

感谢您的帮助!

最佳答案

使用变量作为 xsl:sort 选择条件的 XPath 的一部分

<xsl:for-each select="gpx:gpx/gpx:wpt">
<xsl:sort select="grdspk:cache/grdspk:*[local-name()=$sort_by]"/>
<!--additional logic goes here-->
</xsl:for-each>

关于sorting - XSL 中的条件排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16993816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com