<?xml version="1.0" encoding="UTF-8"?>
<accountList>
<previousAccount>
<account>
<lastName>NASH</lastName>
<accountStatus>REMOVED</accountStatus>
<accNo>8D</accNo>
</account>
<account>
<lastName>ADOGA</lastName>
<accountStatus>REMOVED</accountStatus>
<accNo>8A</accNo>
</account>
<account>
<lastName>LUCAS</lastName>
<accountStatus>HOLD</accountStatus>
<accNo>9A</accNo>
</account>
<account>
<lastName>DONALD</lastName>
<accountStatus>HOLD</accountStatus>
<accNo>10D</accNo>
</account>
<account>
<accountStatus>HOLD</accountStatus>
<lastName>LONDON</lastName>
<accNo>10B</accNo>
</account>
</previousAccount>
<account>
<Title>Mr</Title>
<firstName>RICHARD</firstName>
<lastName>JOHN</lastName>
<city>london</city>
<accNo>5A</accNo>
</account>
<account>
<Title>Mr</Title>
<firstName>xxx</firstName>
<lastName>JOHN</lastName>
<city>London</city>
<accNo>5D</accNo>
</account>
<account>
<Title>Mr</Title>
<firstName>HEWIT</firstName>
<lastName>JOHN</lastName>
<city>LONDON</city>
<accNo>20B</accNo>
</account>
<account>
<Title>Mr</Title>
<firstName>xxx</firstName>
<lastName>JOHN</lastName>
<city>LONDON</city>
<accNo>21D</accNo>
</account>
<account>
<Title>Mr</Title>
<firstName>KEVIN</firstName>
<lastName>PETE</lastName>
<city>LONDON</city>
<accNo>5F</accNo>
</account>
</accountList>
xslt コード
<xsl:stylesheet version="2.0"
xsi:schemaLocation="http://www.w3.org/1999/XSL/Transform file:/C:/Users/n434947/Desktop/workspace/SonicXSLT/BA xslt page.xsd"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="text"/>
<xsl:variable name="newline">
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:template match="accountList">
<xsl:for-each-group select="descendant::account" group-starting-with="*[firstName != 'xxx' or lastName != preceding-sibling::*[1]/lastName]">
<xsl:sort select="accNo" data-type="number"/>
<xsl:value-of select="accNo"/>
<xsl:text> </xsl:text>
<xsl:value-of select="accountStatus"/>
<xsl:text> </xsl:text>
<xsl:value-of select="lastName"/>
<xsl:value-of select="$newline"/>
</xsl:for-each-group>
</xsl:template>
私の要件では、異なるノードである accNo を並べ替える必要がありました。これを言葉ではなくコードで説明すると、accountList/previousAccount/account/accNo accountList/account/accNo のようになります。
私は子孫を使用しましたが、これは私の要件に対してうまく機能していません。ここでは、2 つのノードに対して 2 つの for-each を使用し、別々に並べ替えました。
実際の出力
8D REMOVED NASH
8A REMOVED ADOGA
9A HOLD LUCAS
10D HOLD DONALD
10B HOLD LONDON
5A JOHN
20B JOHN
5F PETE
出力を期待する
5A JOHN
5F PETE
8A REMOVED ADOGA
8D REMOVED NASH
9A HOLD LUCAS
10B HOLD LONDON
10D HOLD DONALD
20B JOHNaccNo will be in sorted manner.
主な問題は、2A、2B、3B、3G のような英数字の組み合わせでソートできないことです。