定制SORT XSL? [英] CUSTOM SORT XSL?

查看:55
本文介绍了定制SORT XSL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的XML结构

输入:-

<MYDATA>
     <DETAILS>
       <DESCRIPTION>EASE</DESCRIPTION>
     </DETAILS>

     <DETAILS>
       <DESCRIPTION>COMPLEX</DESCRIPTION>
     </DETAILS>

     <DETAILS>
       <DESCRIPTION>SIMPLE</DESCRIPTION>
     </DETAILS>
</MYDATA>

我想使用xsl排序显示这样的内容,这意味着自定义排序我想显示简单的第二种轻松性和第三种复杂性

I want to display like this using xsl sort it mean custom sort i want to display firts simple second ease and third complex

输出:-

<MYDATA>

     <DETAILS>
       <DESCRIPTION>SIMPLE</DESCRIPTION>
     </DETAILS>


     <DETAILS>
       <DESCRIPTION>EASE</DESCRIPTION>
     </DETAILS>

     <DETAILS>
       <DESCRIPTION>COMPLEX</DESCRIPTION>
     </DETAILS>

        </MYDATA>

推荐答案

从Jose的想法开始,这里的代码更少:

Starting from Jose's idea, here is something with less code:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:variable name="DifficultyLevel">EASE|SIMPLE|COMPLEX|</xsl:variable>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="MYDATA">
    <xsl:apply-templates select="@* | node()">
      <xsl:sort order="ascending" select="string-length(substring-before($DifficultyLevel, DETAILS/DESCRIPTION))"/>
    </xsl:apply-templates>
  </xsl:template>
</xsl:stylesheet>

这篇关于定制SORT XSL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆