如果按其他两个元素(姓氏,名字)'进行分组,请建议如何对升序中的元素内容(serno)进行排序。分组正在发生但无法对“服务”的数字值进行排序。元素内容。 (XSLT2)
XML:
<!DOCTYPE index [<!ENTITY Racute "Ŕ"><!ENTITY racute "ŕ">]>
<index>
<cmindexnote>This index is cumulative for volume 65</cmindexnote>
<issue>v65n</issue>
<author><lastname>Rudra</lastname><firstname>TP</firstname>
<refserial><serno>14</serno><serno>24</serno></refserial></author>
<author><lastname>Rudra</lastname><firstname>TP</firstname>
<refserial><serno>4</serno></refserial></author>
<author><lastname>Rudra</lastname><firstname>AP</firstname>
<refserial><serno>14</serno></refserial></author>
<author><lastname>Rudramuni</lastname><firstname>CP</firstname>
<refserial><serno>14</serno></refserial></author>
<author><lastname>Rudramuni</lastname><firstname>AP</firstname>
<refserial><serno>24</serno></refserial></author>
<author><lastname>Rudŕamuni</lastname><firstname>AP</firstname>
<refserial><serno>24</serno></refserial></author>
<author><lastname>Rudramuni</lastname><firstname>AP</firstname>
<refserial><serno>224</serno></refserial></author>
<author><lastname>Rudramuni</lastname><firstname>TP</firstname>
<refserial><serno>10</serno></refserial></author>
<author><lastname>Rudramuni</lastname><firstname>AP</firstname>
<refserial><serno>9</serno></refserial></author>
<author><lastname>Rudresh</lastname><firstname>TP</firstname>
<refserial><serno>11</serno></refserial></author>
<author><lastname>Ŕudramuni</lastname><firstname>TP</firstname>
<refserial><serno>19</serno></refserial></author>
</index>
XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="no" use-character-maps="chars"/>
<xsl:character-map name="chars">
<xsl:output-character character="Ŕ" string="&Racute;"/>
<xsl:output-character character="ŕ" string="&racute;"/>
</xsl:character-map>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy>
</xsl:template>
<xsl:template match="index">
<cmindexnote><xsl:value-of select="cmindexnote"/></cmindexnote>
<issue><xsl:value-of select="issue"/></issue>
<xsl:for-each-group select="author" group-by="concat(lastname, firstname)">
<xsl:sort select="lastname" collation="http://saxon.sf.net/collation?lang=en&ignore-modifiers=yes"/>
<xsl:sort select="current-grouping-key()" collation="http://saxon.sf.net/collation?lang=en&ignore-modifiers=yes"/>
<!--xsl:sort select="number(../serno)"/-->
<author>
<lastname><xsl:value-of select="*[1]"/></lastname>
<firstname><xsl:value-of select="*[2]"/></firstname>
<refserial>
<xsl:for-each-group select="current-group()" group-by="refserial">
<xsl:apply-templates select="current-group()">
<xsl:sort select="number(serno)"/>
</xsl:apply-templates>
</xsl:for-each-group>
</refserial>
</author>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="author">
<xsl:apply-templates select="node() except (lastname, firstname)"/>
</xsl:template>
<xsl:template match="refserial">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
必需的OutPut:
<?xml version="1.0" encoding="UTF-8"?><cmindexnote>This index is cumulative for volume 65</cmindexnote><issue>v65n</issue>
<author><lastname>Rudra</lastname><firstname>AP</firstname>
<refserial><serno>14</serno></refserial></author>
<author><lastname>Rudra</lastname><firstname>TP</firstname>
<refserial><serno>4</serno><serno>14</serno><serno>24</serno></refserial></author>
<author><lastname>Rudramuni</lastname><firstname>AP</firstname>
<refserial><serno>9</serno><serno>24</serno><serno>224</serno></refserial></author>
<author><lastname>Rudŕamuni</lastname><firstname>AP</firstname>
<refserial><serno>24</serno></refserial></author>
<author><lastname>Rudramuni</lastname><firstname>CP</firstname>
<refserial><serno>14</serno></refserial></author>
<author><lastname>Rudramuni</lastname><firstname>TP</firstname>
<refserial><serno>10</serno></refserial></author>
<author><lastname>Ŕudramuni</lastname><firstname>TP</firstname>
<refserial><serno>19</serno></refserial></author>
<author><lastname>Rudresh</lastname><firstname>TP</firstname>
<refserial><serno>11</serno></refserial></author>
答案 0 :(得分:1)
这对你有用吗?
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" use-character-maps="chars"/>
<xsl:character-map name="chars">
<xsl:output-character character="Ŕ" string="&Racute;"/>
<xsl:output-character character="ŕ" string="&racute;"/>
</xsl:character-map>
<xsl:template match="/index">
<xsl:copy-of select="cmindexnote | issue"/>
<xsl:for-each-group select="author" group-by="concat(lastname, firstname)">
<xsl:sort select="lastname" collation="http://saxon.sf.net/collation?lang=en&ignore-modifiers=yes"/>
<xsl:sort select="firstname" collation="http://saxon.sf.net/collation?lang=en&ignore-modifiers=yes"/>
<author>
<xsl:copy-of select="lastname | firstname"/>
<refserial>
<xsl:for-each select="current-group()/refserial/serno">
<xsl:sort select="." data-type="number" order="ascending"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</refserial>
</author>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>