Сортировка текста по признаку следующего брата - XSLT - PullRequest
0 голосов
/ 10 апреля 2020

Возможна ли сортировка текста на основе следующего брата, когда он получает то же значение атрибута, и не сортировки текста, если он приходит start-with text Generally. Текст начинается только с одного слова и начинается с Word и Di git Пример 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>

Не уверен, Как отсортировать текст по условию? Сортировка текста только начало одного слова и начало Word и Di git Пример S corporation, Co-sale, five504, seven7(a). Помеченное изображение enter image description here

1 Ответ

1 голос
/ 10 апреля 2020

На основе ваших комментариев вы хотите отсортировать игнорируя регистр и игнорируя символы, такие как пробелы или знаки препинания; в 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, проверьте, можете ли вы использовать это в своей среде или ваш процессор поддерживает используемые параметры сопоставления.

...