Xml XSLT排序问题w/包含单个和两位数文本和数字的字符串

Xml XSLT排序问题w/包含单个和两位数文本和数字的字符串,xml,xslt,Xml,Xslt,我正在寻找帮助,以解决我在将XSLT样式表应用于基本XML文件时遇到的一个问题,该文件将为我们正在构建的门户输出基本HTML。具体地说,我正试图基于title元素将a应用于我输出的内容,title元素包括文本、一位数和两位数,sort元素将两位数放在一位数之前,请参见下面的示例: 示例XML源文件: <?xml version="1.0" encoding="UTF-8"?> <TitleList> <book> <

我正在寻找帮助,以解决我在将XSLT样式表应用于基本XML文件时遇到的一个问题,该文件将为我们正在构建的门户输出基本HTML。具体地说,我正试图基于title元素将a应用于我输出的内容,title元素包括文本、一位数和两位数,sort元素将两位数放在一位数之前,请参见下面的示例:

示例XML源文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <TitleList>
    <book>
        <title>Book 1: Part 3. Buying and Selling Stuff</title>
        <author>Jon Doe</author>
        <PubDate>2010</PubDate>
     </book>
     <book>
      <title>Book 1: Part 7. Making Stuff</title>
      <author>Jane Doe</author>
      <PubDate>2012</PubDate>
      </book>
      <book>
        <title>Book 1: Part 8. The Art of Creating Things </title>
        <author>Jon Doe</author>
        <PubDate>2013</PubDate>
      </book>
     <book>
      <title>Book 1: Part 10. Stuff Happens</title>
      <author>Jane Doe</author>
      <PubDate>2014</PubDate>
     </book>
     </TitleList>
XSLT示例:

     <?xml version="1.0" encoding="UTF-8"?>
     <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
       exclude-result-prefixes="xs"
       version="1.0">
<xsl:output method="html" encoding="UTF-8" />
<xsl:template match="/">
    <html>
        <head></head>
        <body>
           <div id="titleList">
               <table>
                   <tr>
                       <th>Title List</th>
                   </tr>
                   <tr>
                       <xsl:call-template name="retrieveTitles"></xsl:call-template>
                   </tr>
               </table>
           </div> 
        </body>
    </html>
</xsl:template>
<xsl:template name="retrieveTitles">
    <xsl:for-each select="TitleList/book">
     <xsl:sort select="title" /> 
     <tr>   
      <td>  
        <xsl:value-of select="title"/>
      </td>
        <td>
            <xsl:value-of select="author" />
        </td>
        <td>
            <xsl:value-of select="PubDate"/>
        </td>
     </tr>   
    </xsl:for-each>
  </xsl:template>
  </xsl:stylesheet>
标题无序的结果HTML:

    <html>
     <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     </head>
     <body>
     <div id="titleList">
     <table>
        <tr>
           <th>Title List</th>
        </tr>
        <tr>
           <tr>
              <td>Book 1: Part 10. Stuff Happens</td>
              <td>Jane Doe</td>
              <td>2014</td>
           </tr>
           <tr>
              <td>Book 1: Part 3. Buying and Selling Stuff</td>
              <td>Jon Doe</td>
              <td>2010</td>
           </tr>
           <tr>
              <td>Book 1: Part 7. Making Stuff</td>
              <td>Jane Doe</td>
              <td>2012</td>
           </tr>
           <tr>
              <td>Book 1: Part 8. The Art of Creating Things </td>
              <td>Jon Doe</td>
              <td>2013</td>
           </tr>
        </tr>
     </table>
  </div>
    </body>
   </html>  
如何配置XSLT脚本的排序元素,以确保在从一位数跳转到两位数时标题是连续排序的?谢谢你的时间

问候,


> P>将手头问题最小化的例子,考虑如下:

<xsl:template match="/TitleList">
    <table>
        <xsl:apply-templates select="book">
            <xsl:sort select="substring-before(substring-after(title, 'Book ' ), ':')" data-type="number" order="ascending"/>
            <xsl:sort select="substring-before(substring-after(title, 'Part ' ), '.')" data-type="number" order="ascending"/>
        </xsl:apply-templates>
    </table>
</xsl:template>

<xsl:template match="book">
    <tr>
        <td>  
            <xsl:value-of select="title"/>
        </td>
    </tr>       
</xsl:template>

成功了!我将您提供的排序选择功能合并到我的环境中,并且排序正确。我感到鼓舞的是,你的建议包括子字符串之前,因为我正在看,最初,但你帮助填补了我错过的部分!非常感谢-干杯!