根据以下同级词排序-XSLT

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了根据以下同级词排序-XSLT相关的知识,希望对你有一定的参考价值。

是否有可能在属性值相同时根据以下同级对文本进行排序,如果是start-with text Generally,则不对文本进行排序。文本仅以单个单词开头,并以单词和数字开头示例S corporation, Co-sale, five504, seven7(a).在此XML中三种类型的属性值输入文件

    <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>

预期输出

    <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).标记图像enter image description here

答案

根据您的评论,您希望排序时忽略大小写并忽略诸如空格或标点符号之类的符号;在XSLT中(至少3,至少在XSLT 2中也可能,一般情况下,对此类功能的支持可能取决于处理器),您可以对该参数使用归类,例如

<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使用Saxon 9.8 HE似乎有正确的顺序,测试您是否可以在环境中使用它,或者处理器是否支持使用的归类参数。

以上是关于根据以下同级词排序-XSLT的主要内容,如果未能解决你的问题,请参考以下文章

XSLT 对特定同级进行分组

使用 XSLT 将父级添加到选定的同级

将 XSLT 转换的 XML 片段写入 XMLStreamWriter

XSLT 中的同级选择问题

如何为 XSLT 代码片段配置 CruiseControl 的 C# 版本?

Java 后台接口实现同级拖拽排序代码示例