<?xml version="1.0" encoding="UTF-8"?>
<accountList>
<previousAccount>
<account>
<name>NASH</name>
<accountStatus>REMOVED</accountStatus>
<accNo>1</accNo>
</account>
<account>
<name>ADOGA</name>
<accountStatus>REMOVED</accountStatus>
<accNo>8</accNo>
</account>
<account>
<name>LUCAS</name>
<accountStatus>HOLD</accountStatus>
<accNo>09</accNo>
</account>
<account>
<name>DONALD</name>
<accountStatus>HOLD</accountStatus>
<accNo>21</accNo>
</account>
<account>
<Title>Miss</Title>
<firstName>HILARI</firstName>
<lastName>WOOD</lastName>
<city>LONDON</city>
<accNo>24</accNo>
</account>
</previousAccount>
<account>
<Title>Mr</Title>
<firstName>RICHARD</firstName>
<lastName>JOHN</lastName>
<city>london</city>
<accNo>02</accNo>
</account>
<account>
<Title>Mr</Title>
<firstName>xxx</firstName>
<lastName>JOHN</lastName>
<city>London</city>
<accNo>17</accNo>
</account>
<account>
<Title>Mr</Title>
<firstName>HEWIT</firstName>
<lastName>JOHN</lastName>
<city>LONDON</city>
<accNo>20</accNo>
</account>
<account>
<Title>Mr</Title>
<firstName>xxx</firstName>
<lastName>JOHN</lastName>
<city>LONDON</city>
<accNo>21</accNo>
</account>
<account>
<Title>Mr</Title>
<firstName>KEVIN</firstName>
<lastName>PETE</lastName>
<city>LONDON</city>
<accNo>07</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" order="ascending"/>
<xsl:if test="previousAccount/account/accountStatus='REMOVED'">
<xsl:value-of select="previousAccount/account[accountStatus='REMOVED']/accNo"/>
</xsl:if>
<xsl:value-of select="previousAccount/account[accountStatus='HOLD']/accNo"/>
<xsl:value-of select="accNo"/>
<xsl:text> </xsl:text>
<xsl:value-of select="lastName"/>
<xsl:text> </xsl:text>
<xsl:value-of select="firstName"/>
<xsl:value-of select="$newline"/>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
在我的要求中,我必须对来自两个不同 X 路径的 accNo 进行排序,如下所示
accountList/previousAccount/account/accNo
accountList/account/accNo
我使用了后代,这不能满足我的要求。请帮我解决这个问题。
实际输出
02 JOHN RICHARD
07 PETE KEVIN
1
20 JOHN HEWIT
24 WOOD HILARI
期望输出
01 REMOVED NASH
02 JOHN RICHARD
07 PETE KEVIN
08 REMOVED ADOGA
09 HOLD LUCAS
20 JOHN HEWIT
24 HOLD DONALD