xml数据分组排序

1、分组、排序xsl
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:key name="categ_key" match="book" use="genre"/>
<xsl:key name="author_key" match="book" use="author"/>

<xsl:template match="/">
    <HTML>
        <HEAD>
            <TITLE>Scootney Publishing: Special Exhibit</TITLE>
            <STYLE>
                h1 {font-family: Arial,Helvetica,Univers,sans-serif;
                    font-size: 18pt; font-weight: bold;
                    background-color: teal;
                    width: 75%}
                h2 {font-family: Arial,Helvetica,Univers,sans-serif;
                    font-size: 14pt; font-weight: bold;
                    background-color: white;
                    width: 75%}
                h3 {font-family: Arial,Helvetica,Univers,sans-serif;
                    font-size: 12pt; font-weight: bold;
                    background-color: gold;
                    width: 75%;
                    border-width: 1;
                    border-style: solid}
            </STYLE>
        </HEAD>
        <BODY>
            <h1>Scootney Publishing: Special Exhibit Catalog</h1>
            <xsl:apply-templates select="catalog" mode="grp_categ"/>
            <xsl:apply-templates select="catalog" mode="grp_author"/>
        </BODY>
    </HTML>
</xsl:template>

<xsl:template match="catalog" mode="grp_categ">
    <h2>Titles Grouped by Genre</h2>
    <xsl:for-each select="book[count(. | key('categ_key', genre)[1])=1]">
        <h3><xsl:value-of select="genre" /></h3>
        <xsl:for-each select="key('categ_key', genre)">
            <xsl:sort select="title"/>
            <TABLE border="0" width="75%">
                <tr>
                    <th width="10%" align="right">Title</th>
                    <td width="90%" align="left"><xsl:value-of select="title" /></td>
                </tr>
                <tr>
                    <th width="10%" align="right">Author</th>
                    <td width="90%" align="left"><xsl:value-of select="author" /></td>
                </tr>
                <tr>
                    <th width="10%" align="right">Copyright</th>
                    <td width="90%" align="left"><xsl:value-of select="publish_date" /></td>
                </tr>
                <tr>
                    <th width="10%" align="right">Price</th>
                    <td width="90%" align="left"><xsl:value-of select="price" /></td>
                </tr>
                <tr>
                    <th width="10%" align="right" valign="top">Summary</th>
                    <td width="90%" align="left" valign="top"><xsl:value-of select="description" /></td>
                </tr>
            </TABLE>
            <hr width="75%" align="left"/>
        </xsl:for-each>
    </xsl:for-each>
</xsl:template>

<xsl:template match="catalog" mode="grp_author">
    <h2>Titles Grouped by Author</h2>
    <xsl:for-each select="book[generate-id() = generate-id(key('author_key', author)[1])]">
        <xsl:sort select="author"/>
        <h3><xsl:value-of select="author" /></h3>
        <xsl:for-each select="key('author_key', author)">
            <xsl:sort select="title"/>
            <TABLE border="0" width="75%">
                <tr>
                    <th width="10%" align="right">Title</th>
                    <td width="90%" align="left"><xsl:value-of select="title" /></td>
                </tr>
                <tr>
                    <th width="10%" align="right">Genre</th>
                    <td width="90%" align="left"><xsl:value-of select="genre" /></td>
                </tr>
                <tr>
                    <th width="10%" align="right">Copyright</th>
                    <td width="90%" align="left"><xsl:value-of select="publish_date" /></td>
                </tr>
                <tr>
                    <th width="10%" align="right">Price</th>
                    <td width="90%" align="left"><xsl:value-of select="price" /></td>
                </tr>
                <tr>
                    <th width="10%" align="right" valign="top">Summary</th>
                    <td width="90%" align="left" valign="top"><xsl:value-of select="description" /></td>
                </tr>
            </TABLE>
            <hr width="75%" align="left"/>
        </xsl:for-each>
    </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
2、xml数据
<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies,
      an evil sorceress, and her own childhood to become queen
      of the world.</description>
   </book>
   <book id="bk103">
      <author>Corets, Eva</author>
      <title>Maeve Ascendant</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-11-17</publish_date>
      <description>After the collapse of a nanotechnology
      society in England, the young survivors lay the
      foundation for a new society.</description>
   </book>
   <book id="bk104">
      <author>Corets, Eva</author>
      <title>Oberon's Legacy</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-03-10</publish_date>
      <description>In post-apocalypse England, the mysterious
      agent known only as Oberon helps to create a new life
      for the inhabitants of London. Sequel to Maeve
      Ascendant.</description>
   </book>
   <book id="bk105">
      <author>Corets, Eva</author>
      <title>The Sundered Grail</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-09-10</publish_date>
      <description>The two daughters of Maeve, half-sisters,
      battle one another for control of England. Sequel to
      Oberon's Legacy.</description>
   </book>
   <book id="bk106">
      <author>Randall, Cynthia</author>
      <title>Lover Birds</title>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-09-02</publish_date>
      <description>When Carla meets Paul at an ornithology
      conference, tempers fly as feathers get ruffled.</description>
   </book>
   <book id="bk107">
      <author>Thurman, Paula</author>
      <title>Splish Splash</title>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>A deep sea diver finds true love twenty
      thousand leagues beneath the sea.</description>
   </book>
   <book id="bk108">
      <author>Knorr, Stefan</author>
      <title>Creepy Crawlies</title>
      <genre>Horror</genre>
      <price>4.95</price>
      <publish_date>2000-12-06</publish_date>
      <description>An anthology of horror stories about roaches,
      centipedes, scorpions  and other insects.</description>
   </book>
   <book id="bk109">
      <author>Kress, Peter</author>
      <title>Paradox Lost</title>
      <genre>Science Fiction</genre>
      <price>6.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>After an inadvertant trip through a Heisenberg
      Uncertainty Device, James Salway discovers the problems
      of being quantum.</description>
   </book>
   <book id="bk110">
      <author>O'Brien, Tim</author>
      <title>Microsoft .NET: The Programming Bible</title>
      <genre>Computer</genre>
      <price>36.95</price>
      <publish_date>2000-12-09</publish_date>
      <description>Microsoft's .NET initiative is explored in
      detail in this deep programmer's reference.</description>
   </book>
   <book id="bk111">
      <author>O'Brien, Tim</author>
      <title>MSXML3: A Comprehensive Guide</title>
      <genre>Computer</genre>
      <price>36.95</price>
      <publish_date>2000-12-01</publish_date>
      <description>The Microsoft MSXML3 parser is covered in
      detail, with attention to XML DOM interfaces, XSLT processing,
      SAX and more.</description>
   </book>
   <book id="bk112">
      <author>Galos, Mike</author>
      <title>Visual Studio 7: A Comprehensive Guide</title>
      <genre>Computer</genre>
      <price>49.95</price>
      <publish_date>2001-04-16</publish_date>
      <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are
      integrated into a comprehensive development
      environment.</description>
   </book>
</catalog>
3、表单
<DIV ID="idContent">Please Wait while loading view ...</DIV>
onload:
oXml  = new ActiveXObject("Microsoft.XMLDOM")
oXml.async = false
oXml.load("/xxx.nsf/x?ReadForm");

oXsl = new ActiveXObject("Microsoft.XMLDOM")
oXsl.async = false
oXsl.load("/xxx.nsf/y?ReadForm");

strRet = oXml.transformNode(oXsl)
document.all("idContent").innerHTML = strRet;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值