2013-08-07 36 views
1
 <?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它們是不同的nodes.I想我會做的更好的代碼解釋這不是也就是說, 爲accountList/previousAccount /帳號/ ACCNO 爲accountList /帳號/ ACCNO

我用的後裔,這是不工作的罰款,我requirement.Here我用了兩個換分別用於兩個節點和分類separtedly.Last但至少我去t按字母數字組合排序。

實際輸出

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

回答

0

那麼這是一個髒溶液...使用此功能:

<xsl:function name="px:toInteger" as="xs:double"> 
    <xsl:param name="value" as="xs:string"/> 
    <xsl:variable name="letter" select="replace($value, '\d', '')"/> 
    <xsl:variable name="digit" select="xs:integer(replace($value, '\D', ''))" as="xs:integer"/> 
    <xsl:variable name="codepoints" select="xs:integer(string-to-codepoints($letter))" as="xs:integer"/> 
    <xsl:value-of select="$digit + ($codepoints div 100000)"/> 
</xsl:function> 

並調用它在xsl:排序:

<xsl:sort select="px:toInteger(accNo)" data-type="number"/> 

它只是適用於喜歡你的樣本整數+一個字符。

相關問題