首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于以下同级XSLT的文本排序

基于以下同级XSLT的文本排序
EN

Stack Overflow用户
提问于 2020-04-10 09:44:25
回答 1查看 71关注 0票数 0

当出现相同的属性值时,是否可以根据跟随的同级对文本进行排序,而如果文本是start-with text Generally的话,则不对文本排序。文本只启动单个单词,并在此XML中启动单词和数字示例S corporation, Co-sale, five504, seven7(a).,三种类型的属性值。

输入文件

代码语言:javascript
复制
    <document>
    <p specific-use="Main">Accounts and Accounting</p>
    <p specific-use="Sub1">Regulation A offerings, accounting fees for, <xref ref-type="other" rid="none">19.9</xref></p>
    <p specific-use="Sub1">S corporation, accounting closing provision in buy-sell agreement, <xref ref-type="other" rid="none">3.53&#x0192;</xref></p>
    <p specific-use="Sub1">Sarbanes-Oxley Act of 2002, public accounting firms' required registration with Public Company Accounting Oversight Board (PCAOB) under, <xref ref-type="other" rid="none">17.5</xref>, <xref ref-type="other" rid="none">18.9</xref>, <xref ref-type="other" rid="none">20.13</xref></p>
    <p specific-use="Sub1">Stock dividends <emphasis type="roman">versus</emphasis> stock splits, accounting treatment of, <xref ref-type="other" rid="none">18.30</xref></p>
    <p specific-use="Main">Agreements</p>
    <p specific-use="seeAlso"><emphasis type="roman">See also</emphasis> <emphasis type="bold">Contracts</emphasis></p>
    <p specific-use="Sub1">Buy-sell agreements. <emphasis type="roman">See</emphasis> <emphasis type="bold">Buy-Sell Agreement</emphasis></p>
    <p specific-use="Sub1">Co-sale agreement. <emphasis type="roman">See</emphasis> <emphasis type="bold">Right of First Refusal and Co-Sale Agreement</emphasis></p>
    <p specific-use="Sub1">Confidentiality agreements. <emphasis type="roman">See</emphasis> <emphasis type="bold">Confidentiality</emphasis></p>
    <p specific-use="Sub1">Founders, agreements between. <emphasis type="roman">See</emphasis> <emphasis type="bold">Founder of New Business Entity</emphasis></p>
    <p specific-use="Sub1">Investment agreement. <emphasis type="roman">See</emphasis> <emphasis type="bold">Investment Agreement</emphasis></p>
    <p specific-use="Main">CAN-SPAM Act</p>
    <p specific-use="Sub1">Generally, <xref ref-type="other" rid="none">13.24</xref></p>
    <p specific-use="Main">Capital</p>
    <p specific-use="seeAlso"><emphasis type="roman">See also</emphasis> <emphasis type="bold">Venture Capital</emphasis></p>
    <p specific-use="Sub1">Generally, <xref ref-type="other" rid="none">1.1</xref></p>
    <p specific-use="Sub1">Attorney's role in obtaining capital</p>
    <p specific-use="Sub2">Generally, <xref ref-type="other" rid="none">1.1</xref></p>
    <p specific-use="Sub2">Appropriate sources of capital, identification of, <xref ref-type="other" rid="none">1.6</xref></p>
    <p specific-use="Sub2">Business plan, preparation of, <xref ref-type="other" rid="none">1.5</xref></p>
    <p specific-use="Sub1">Small Business Administration (SBA)</p>
    <p specific-use="Sub2">Generally, <xref ref-type="other" rid="none">1.11</xref></p>
    <p specific-use="Sub2">five504 loan program, <xref ref-type="other" rid="none">1.11</xref>, <xref ref-type="other" rid="none">1.11C</xref></p>
    <p specific-use="Sub2">seven7(a) loan program, <xref ref-type="other" rid="none">1.11</xref>, <xref ref-type="other" rid="none">1.11B</xref></p>
    <p specific-use="Sub2">Direct loans by SBA, <xref ref-type="other" rid="none">1.12</xref></p>
    <p specific-use="Sub2">Guaranty of loan by SBA, <xref ref-type="other" rid="none">1.11</xref>, <xref ref-type="other" rid="none">1.13</xref></p>
    <p specific-use="Sub2">Maximum maturity for loan, <xref ref-type="other" rid="none">1.11B</xref></p>
    <p specific-use="Sub2">Specialized SBA loan programs, <xref ref-type="other" rid="none">1.11E</xref></p>
    <p specific-use="Sub1">Sources of capital</p>
    <p specific-use="Main">Buy-Sell Agreement</p>
    <p specific-use="Sub1">Generally, <xref ref-type="other" rid="none">3.13</xref>, <xref ref-type="other" rid="none">4.28</xref></p>
    <p specific-use="Sub1">Redemption format, <xref ref-type="other" rid="none">3.19</xref></p>
    <p specific-use="Sub1">S corporations. <emphasis type="roman">See</emphasis> <emphasis type="bold">S Corporations</emphasis></p>
    <p specific-use="Sub1">Shareholder buy-sell agreement</p>
</document>

预期输出

代码语言:javascript
复制
    <document>
    <p specific-use="Main">Accounts and Accounting</p>
    <p specific-use="Sub1">Regulation A offerings, accounting fees for, <xref ref-type="other" rid="none">19.9</xref></p>
    <p specific-use="Sub1">Sarbanes-Oxley Act of 2002, public accounting firms' required registration with Public Company Accounting Oversight Board (PCAOB) under, <xref ref-type="other" rid="none">17.5</xref>, <xref ref-type="other" rid="none">18.9</xref>, <xref ref-type="other" rid="none">20.13</xref></p>
    <p specific-use="Sub1">S corporation, accounting closing provision in buy-sell agreement, <xref ref-type="other" rid="none">3.53&#x0192;</xref></p>
    <p specific-use="Sub1">Stock dividends <emphasis type="roman">versus</emphasis> stock splits, accounting treatment of, <xref ref-type="other" rid="none">18.30</xref></p>
    <p specific-use="Main">Agreements</p>
    <p specific-use="seeAlso"><emphasis type="roman">See also</emphasis> <emphasis type="bold">Contracts</emphasis></p>
    <p specific-use="Sub1">Buy-sell agreements. <emphasis type="roman">See</emphasis> <emphasis type="bold">Buy-Sell Agreement</emphasis></p>
    <p specific-use="Sub1">Confidentiality agreements. <emphasis type="roman">See</emphasis> <emphasis type="bold">Confidentiality</emphasis></p>
    <p specific-use="Sub1">Co-sale agreement. <emphasis type="roman">See</emphasis> <emphasis type="bold">Right of First Refusal and Co-Sale Agreement</emphasis></p>
    <p specific-use="Sub1">Founders, agreements between. <emphasis type="roman">See</emphasis> <emphasis type="bold">Founder of New Business Entity</emphasis></p>
    <p specific-use="Sub1">Investment agreement. <emphasis type="roman">See</emphasis> <emphasis type="bold">Investment Agreement</emphasis></p>
    <p specific-use="Main">CAN-SPAM Act</p>
    <p specific-use="Sub1">Generally, <xref ref-type="other" rid="none">13.24</xref></p>
    <p specific-use="Main">Capital</p>
    <p specific-use="seeAlso"><emphasis type="roman">See also</emphasis> <emphasis type="bold">Venture Capital</emphasis></p>
    <p specific-use="Sub1">Generally, <xref ref-type="other" rid="none">1.1</xref></p>
    <p specific-use="Sub1">Attorney's role in obtaining capital</p>
    <p specific-use="Sub2">Generally, <xref ref-type="other" rid="none">1.1</xref></p>
    <p specific-use="Sub2">Appropriate sources of capital, identification of, <xref ref-type="other" rid="none">1.6</xref></p>
    <p specific-use="Sub2">Business plan, preparation of, <xref ref-type="other" rid="none">1.5</xref></p>
    <p specific-use="Sub1">Small Business Administration (SBA)</p>
    <p specific-use="Sub2">Generally, <xref ref-type="other" rid="none">1.11</xref></p>
    <p specific-use="Sub2">Direct loans by SBA, <xref ref-type="other" rid="none">1.12</xref></p>
    <p specific-use="Sub2">five504 loan program, <xref ref-type="other" rid="none">1.11</xref>, <xref ref-type="other" rid="none">1.11C</xref></p>
    <p specific-use="Sub2">Guaranty of loan by SBA, <xref ref-type="other" rid="none">1.11</xref>, <xref ref-type="other" rid="none">1.13</xref></p>
    <p specific-use="Sub2">Maximum maturity for loan, <xref ref-type="other" rid="none">1.11B</xref></p>
    <p specific-use="Sub2">seven7(a) loan program, <xref ref-type="other" rid="none">1.11</xref>, <xref ref-type="other" rid="none">1.11B</xref></p>
    <p specific-use="Sub2">Specialized SBA loan programs, <xref ref-type="other" rid="none">1.11E</xref></p>
    <p specific-use="Sub1">Sources of capital</p>
    <p specific-use="Main">Buy-Sell Agreement</p>
    <p specific-use="Sub1">Generally, <xref ref-type="other" rid="none">3.13</xref>, <xref ref-type="other" rid="none">4.28</xref></p>
    <p specific-use="Sub1">Redemption format, <xref ref-type="other" rid="none">3.19</xref></p>
    <p specific-use="Sub1">S corporations. <emphasis type="roman">See</emphasis> <emphasis type="bold">S Corporations</emphasis></p>
    <p specific-use="Sub1">Shareholder buy-sell agreement</p>
</document>

不确定,如何根据条件对文本进行排序?

排序文本仅启动单个单词和启动单词和数字示例S corporation, Co-sale, five504, seven7(a). 标记的图像

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-10 18:03:01

根据您的注释,您希望对忽略大小写进行排序,忽略空格或标点符号等符号;在XSLT中(至少在XSLT 2中,通常对这些特性的支持可能取决于处理器),您可以使用带有该参数的排序规则。

代码语言:javascript
复制
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="#all"
    version="3.0">

  <xsl:param name="sort-if" as="xs:string*" select="'S corporation', 'Co-sale', 'five504', 'seven7'"/>

  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:output indent="yes" suppress-indentation="p"/>

  <xsl:template match="document">
      <xsl:copy>
          <xsl:for-each-group select="p" composite="yes" group-adjacent="@specific-use, not(starts-with(., 'Generally'))">
              <xsl:choose>
                  <xsl:when test="current-grouping-key()[2]">
                      <xsl:apply-templates select="current-group()">
                          <xsl:sort select="." collation="http://www.w3.org/2013/collation/UCA?lang=en;ignore-case=yes;ignore-symbols=yes"/>
                  </xsl:apply-templates>
                      </xsl:apply-templates>
                  </xsl:when>
                  <xsl:otherwise>
                      <xsl:apply-templates select="current-group()"/>
                  </xsl:otherwise>
              </xsl:choose>
          </xsl:for-each-group>
      </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

https://xsltfiddle.liberty-development.net/93dFepK/2似乎有正确的顺序使用Saxon9.8HE,测试您是否可以在您的环境中使用它,或者您的处理器是否支持使用的排序规则参数。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61137684

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档