根据以下兄弟对文本进行排序 - XSLT
Sorting text based on following sibling - XSLT
是否可以在出现相同属性值时根据后续兄弟对文本进行排序,而在出现start-with text Generally
时不对文本进行排序。 Text start only single word and start Word and Digit Example S corporation, Co-sale, five504, seven7(a).
In this 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ƒ</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ƒ</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).
标记图像
根据您的评论,您希望忽略大小写并忽略空格或标点符号等符号;在 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 的顺序似乎正确,请测试您是否可以在您的环境中使用它,或者您的处理器是否支持使用的排序规则参数。
是否可以在出现相同属性值时根据后续兄弟对文本进行排序,而在出现start-with text Generally
时不对文本进行排序。 Text start only single word and start Word and Digit Example S corporation, Co-sale, five504, seven7(a).
In this 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ƒ</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ƒ</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).
标记图像
根据您的评论,您希望忽略大小写并忽略空格或标点符号等符号;在 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 的顺序似乎正确,请测试您是否可以在您的环境中使用它,或者您的处理器是否支持使用的排序规则参数。