user2423959
user2423959

Reputation: 834

Converting a number and linking it

i have the below xml document.

<chapter>
    <para>
        <phrase>3.006</phrase> Parties may agree to undergo a particular ADR technique in the event of a dispute between them by entering into an ADR agreement. There are a number of ADR procedures to choose from. The procedure may involve only the parties to the dispute (such as negotiation), or may involve an independent third party. The third party may facilitate the parties&#x2019; own consensual resolution of the dispute (as in mediation/conciliation), or the third party may give an opinion on the issues in dispute (as is usually the case with a Dispute Review Board). The third party may produce a binding decision (such as adjudication) or a non-binding decision (such as expert determination). These various ADR techniques will be discussed (in paras.3.007-3.111) below. They can be compared with partnering which involves dispute avoidance (see paras.3.112 to 3.127), and the more traditional arbitration and litigation (see paras.3.128 to 3.172).
    </para>
    <para>
        <phrase>3.008</phrase> It may be stating the obvious, but negotiation can (and should) be used on its own to resolve a dispute. In fact, many dispute resolution clauses in commercial contracts require the parties to try to resolve disputes between them by negotiation prior to the initiation of any arbitration or legal proceedings. A common dispute resolution clause will use words to the effect of &#x201C;the parties shall use their best efforts in good faith to reach a reasonable and equitable resolution&#x201D; (the concept of good faith negotiation will be discussed further in para.3.020 below). Alternatively, negotiation can be used as a facilitating technique in one of the many other methods of dispute resolution. It is of particular importance in mediation or conciliation (which is discussed in para.3.027 below).
    </para>
    <para>Arbitration agreements are discussed in more detail in Chapter 9.</para>
</chapter>

here actually i want an xslt that converts a number into hyperlink as below.

Case1:
if something like 3.128 is found, it should be converted to

<a href="er:#AHK_CH_03/P03-128">3.128</a> 

Case 2:
if some thing like Chapter 9 is found, it should be converted to

<a href="er:#AHK_CH_18>Chapter 9</a>.

please let me know how do i do it.

Thanks.

Upvotes: 0

Views: 61

Answers (1)

Navin Rawat
Navin Rawat

Reputation: 3138

With XSLT 2.0 we may generate given XSLT to get desired output:

XSLT:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="text()">
    <xsl:analyze-string select="." regex="(([Cc]hapter)\s(\d+))">
      <xsl:matching-substring>
        <a href="{concat('er:#AHK_CH_',regex-group(3))}">
          <xsl:value-of select="."/>
        </a>
      </xsl:matching-substring>
      <xsl:non-matching-substring>
        <xsl:analyze-string select="." regex="([0-9])\.([0-9]+)">
          <xsl:matching-substring>
            <a
              href="{concat('er:#AHK_CH_',format-number(number(regex-group(1)),'00'),'/P',format-number(number(regex-group(1)),'00'),'-',regex-group(2))}">
              <xsl:value-of select="."/>
            </a>
          </xsl:matching-substring>
          <xsl:non-matching-substring>
            <xsl:value-of select="."/>
          </xsl:non-matching-substring>
        </xsl:analyze-string>
      </xsl:non-matching-substring>
    </xsl:analyze-string>
  </xsl:template>

</xsl:stylesheet>

output:

    <a href="er:#AHK_CH_03/P03-006">3.006</a> Parties may agree to undergo a particular ADR technique in the event of a dispute between them by entering into an ADR agreement. There are a number of ADR procedures to choose from. The procedure may involve only the parties to the dispute (such as negotiation), or may involve an independent third party. The third party may facilitate the parties’ own consensual resolution of the dispute (as in mediation/conciliation), or the third party may give an opinion on the issues in dispute (as is usually the case with a Dispute Review Board). The third party may produce a binding decision (such as adjudication) or a non-binding decision (such as expert determination). These various ADR techniques will be discussed (in paras.<a href="er:#AHK_CH_03/P03-007">3.007</a>-<a href="er:#AHK_CH_03/P03-111">3.111</a>) below. They can be compared with partnering which involves dispute avoidance (see paras.<a href="er:#AHK_CH_03/P03-112">3.112</a> to <a href="er:#AHK_CH_03/P03-127">3.127</a>), and the more traditional arbitration and litigation (see paras.<a href="er:#AHK_CH_03/P03-128">3.128</a> to <a href="er:#AHK_CH_03/P03-172">3.172</a>).


    <a href="er:#AHK_CH_03/P03-008">3.008</a> It may be stating the obvious, but negotiation can (and should) be used on its own to resolve a dispute. In fact, many dispute resolution clauses in commercial contracts require the parties to try to resolve disputes between them by negotiation prior to the initiation of any arbitration or legal proceedings. A common dispute resolution clause will use words to the effect of “the parties shall use their best efforts in good faith to reach a reasonable and equitable resolution” (the concept of good faith negotiation will be discussed further in para.<a href="er:#AHK_CH_03/P03-020">3.020</a> below). Alternatively, negotiation can be used as a facilitating technique in one of the many other methods of dispute resolution. It is of particular importance in mediation or conciliation (which is discussed in para.<a href="er:#AHK_CH_03/P03-027">3.027</a> below).

  Arbitration agreements are discussed in more detail in <a href="er:#AHK_CH_9">Chapter 9</a>.

Upvotes: 1

Related Questions