1

我有以下两种 XML 案例。

<pg>1/2/1, 1/4/2, 1/4/7, 1/4/8, 1/9/1, 1A/0/11, 3/0/2, 10/1/6, 12/0/2, 12/3/1, 15/2/1, 17/5/2, 19/0/2A, 25/1/1, 28/0/2, 41/1/5, 55/0/2, 55/1/1, 62/3/3, 65/0/2, 65/2/1, 65/4/1, 65/5/4, 69/4/1, 70/0/3, 72/2/11, 72/2/19, 72/6/5, 75/0/2, 75/1/18, 76/0/2, 77/0/3, 78/0/2, 81/1/12, 92/0/2, 100/3/1, 103/0/52, 103/0/53, 121/0/2A, PD1.1/1, PD5.1/2, PD5.4/1, PD18.1/49, B/74, B/75, B/76, P1/1, P1/2, P3/0/2, P3/0/3, P–FM–D4, D4/65, E1/28/1, F1/30/5, F1/35/2, F1/35/5, H1/3, H9/2, J1/60, M2/18, Q1/25/2, R1/10/1, U1/0/4, U1/0/22, U1/112/2, V1/0/2, V2/0/1, V2/1/0 </pg>

<pg>4/9/2, 5/4, 6/2/9, 6/L/27, 13/9/3, 13/9/14, 14/0/2, 14/0/4, 14/1/1—14/1/5, 14/1/7—14/1/10, 14/2/1—14/2/3, 14/2/5, 14/2/7, 14/4/1, 14/4/3, 14/4/4, 14/4/8—14/4/10, 14/4/12, 14/4/14, 14/4/18, 14/4/19, 14/4/21, 14/4/22, 14/4/25, 14/4/26, 14/4/29, 14/4/30, 14/4/33, 14/4/34, 14/4/36, 14/4/37, 14/4/41, 14/4/42, 14/5/1, 14/6/1, 14/7/1—14/7/6, 14/7/8, 14/7/9, 14/7/15, 14/7/18, 14/8/1, 14/8/2, 14/9/1, 14/10/1, 14/11/1, 14A/0/2, 14A/0/3, 14A/2/7, 15/2/3, 15/3/6, 15/4/11, 16/4/9, 16/7/3, 16/8/8, 16/8/10, 16/11/1, 18/1/3, 18/2/5, 19/2/2, 19/2/9, 20/0/2, 20/4/3, 20/8/23, 22/8, 23/3/3, 24/7/1, 25/1, 27/3/6, 28/4/1, 29/10, 29/10/3, 29/11/1, 29/12/4, 32/6/4, 32/6/14, 32/13/8, 33/0/3, 33/4/1, 42/1/4, 42/2/4, 43/1/5, 45/4/2, 47/1/1, 47/1/2, 58/1/4, 59/0/9, 59/0/47, 59/0/55, 59/4, 59/10/35, 62/4/2, 62/App/21, 62/App/27, 71/2/1, 76/6/1, 81/4/2, 81/5/7, 86/0/2, 86/0/3, 86/1/1, 86/1/2, 86/1/3, 86/2/2, 86/4/1, 88/0/2, 88/1/2, 100/3/13, 103/0/26, 103/0/28, 113/0/2, PD8.2/1, PD8.2/2, PD14.1/1, PD16.2/5, E3/0/4</pg>

下面是 XSLT(REGEX)。

            <xsl:analyze-string select="." regex="([0-9]+)/([0-9]+)/([0-9]+)|
            ([0-9]+)([A-Z])/([0-9]+)/([0-9]+)|
            ([0-9]+)/([0-9]+)([A-Z])/([0-9]+)|
            ([A-Z])([0-9]+)/([0-9]+)/([0-9]+)|
            ([0-9]+)/([0-9]+)/([0-9]+)([A-Z])">
                <xsl:matching-substring>
                    <a href="{concat('er:#HKWBV1_ORD_',format-number(number(regex-group(1)),'00'),'/P',format-number(number(regex-group(1)),'0'),'/',regex-group(2),'/',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:#HKWBV1_ORD_',format-number(number(regex-group(1)),'00'),'/P',format-number(number(regex-group(1)),'0'),'/',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>

我正在尝试转换为以下部分

er:#HKWBV1_ORD_01/P1/2/1

这里

er:#HKWBV1_ORD_(content before first slash)/P1(even here number before first slash)/2(content before second slash)/1(content after 2nd slash).

但我/我得到以下结果。

<td class="pgs"><a href="er:#HKWBV1_ORD_01/P1/0/2">1/0/2</a>,<a href="er:#HKWBV1_ORD_01/P1/2/1">1/2/1</a>, <a href="er:#HKWBV1_ORD_01/P1/4/2">1/4/2</a>, <a href="er:#HKWBV1_ORD_01/P1/4/7">1/4/7</a>, <a href="er:#HKWBV1_ORD_01/P1/4/8">1/4/8</a>, <a href="er:#HKWBV1_ORD_01/P1/9/1">1/9/1</a>, 1A/<a href="er:#HKWBV1_ORD_00/P0/11">0/11</a>, <a href="er:#HKWBV1_ORD_03/P3/0/2">3/0/2</a>, <a href="er:#HKWBV1_ORD_10/P10/1/6">10/1/6</a>, <a href="er:#HKWBV1_ORD_12/P12/0/2">12/0/2</a>, <a href="er:#HKWBV1_ORD_12/P12/3/1">12/3/1</a>, <a href="er:#HKWBV1_ORD_15/P15/2/1">15/2/1</a>, <a href="er:#HKWBV1_ORD_17/P17/5/2">17/5/2</a>, <a href="er:#HKWBV1_ORD_19/P19/0/2">19/0/2</a>A, <a href="er:#HKWBV1_ORD_25/P25/1/1">25/1/1</a>, <a href="er:#HKWBV1_ORD_28/P28/0/2">28/0/2</a>, <a href="er:#HKWBV1_ORD_41/P41/1/5">41/1/5</a>, <a href="er:#HKWBV1_ORD_55/P55/0/2">55/0/2</a>, <a href="er:#HKWBV1_ORD_55/P55/1/1">55/1/1</a>, <a href="er:#HKWBV1_ORD_62/P62/3/3">62/3/3</a>, <a href="er:#HKWBV1_ORD_65/P65/0/2">65/0/2</a>, <a href="er:#HKWBV1_ORD_65/P65/2/1">65/2/1</a>, <a href="er:#HKWBV1_ORD_65/P65/4/1">65/4/1</a>, <a href="er:#HKWBV1_ORD_65/P65/5/4">65/5/4</a>, <a href="er:#HKWBV1_ORD_69/P69/4/1">69/4/1</a>, <a href="er:#HKWBV1_ORD_70/P70/0/3">70/0/3</a>, <a href="er:#HKWBV1_ORD_72/P72/2/11">72/2/11</a>, <a href="er:#HKWBV1_ORD_72/P72/2/19">72/2/19</a>, <a href="er:#HKWBV1_ORD_72/P72/6/5">72/6/5</a>, <a href="er:#HKWBV1_ORD_75/P75/0/2">75/0/2</a>, <a href="er:#HKWBV1_ORD_75/P75/1/18">75/1/18</a>, <a href="er:#HKWBV1_ORD_76/P76/0/2">76/0/2</a>, <a href="er:#HKWBV1_ORD_77/P77/0/3">77/0/3</a>, <a href="er:#HKWBV1_ORD_78/P78/0/2">78/0/2</a>, <a href="er:#HKWBV1_ORD_81/P81/1/12">81/1/12</a>, <a href="er:#HKWBV1_ORD_92/P92/0/2">92/0/2</a>, <a href="er:#HKWBV1_ORD_100/P100/3/1">100/3/1</a>, <a href="er:#HKWBV1_ORD_103/P103/0/52">103/0/52</a>, <a href="er:#HKWBV1_ORD_103/P103/0/53">103/0/53</a>, <a href="er:#HKWBV1_ORD_121/P121/0/2">121/0/2</a>A, PD1.<a href="er:#HKWBV1_ORD_01/P1/1">1/1</a>, PD5.<a href="er:#HKWBV1_ORD_01/P1/2">1/2</a>, PD5.<a href="er:#HKWBV1_ORD_04/P4/1">4/1</a>, PD18.<a href="er:#HKWBV1_ORD_01/P1/49">1/49</a>, B/74, B/75, B/76, P<a href="er:#HKWBV1_ORD_01/P1/1">1/1</a>, P<a href="er:#HKWBV1_ORD_01/P1/2">1/2</a>, P<a href="er:#HKWBV1_ORD_03/P3/0/2">3/0/2</a>, P<a href="er:#HKWBV1_ORD_03/P3/0/3">3/0/3</a>, P–FM–D4, D<a href="er:#HKWBV1_ORD_04/P4/65">4/65</a>, E<a href="er:#HKWBV1_ORD_01/P1/28/1">1/28/1</a>, F<a href="er:#HKWBV1_ORD_01/P1/30/5">1/30/5</a>, F<a href="er:#HKWBV1_ORD_01/P1/35/2">1/35/2</a>, F<a href="er:#HKWBV1_ORD_01/P1/35/5">1/35/5</a>, H<a href="er:#HKWBV1_ORD_01/P1/3">1/3</a>, H<a href="er:#HKWBV1_ORD_09/P9/2">9/2</a>, J<a href="er:#HKWBV1_ORD_01/P1/60">1/60</a>, M<a href="er:#HKWBV1_ORD_02/P2/18">2/18</a>, Q<a href="er:#HKWBV1_ORD_01/P1/25/2">1/25/2</a>, R<a href="er:#HKWBV1_ORD_01/P1/10/1">1/10/1</a>, U<a href="er:#HKWBV1_ORD_01/P1/0/4">1/0/4</a>, U<a href="er:#HKWBV1_ORD_01/P1/0/22">1/0/22</a>, U<a href="er:#HKWBV1_ORD_01/P1/112/2">1/112/2</a>, V<a href="er:#HKWBV1_ORD_01/P1/0/2">1/0/2</a>, V<a href="er:#HKWBV1_ORD_02/P2/0/1">2/0/1</a>, V<a href="er:#HKWBV1_ORD_02/P2/1/0">2/1/0</a> </td>

请让我知道如何获得上述格式的输出。我已经收到一个运行良好的回复,但是当我遇到 M-Dash(长连字符)时,连字符前后的字符串将作为单个链接加入。

如果有任何数字像

 D4/65, E1/28/1, F1/30/5, F1/35/2, F1/35/5, H1/3, H9/2, J1/60, M2/18, Q1/25/2, R1/10/1, U1/0/4, U1/0/22, U1/112/2, V1/0/2, V2/0/1, V2/1/0

应转换为

<span class="invalid">D4/65</span>, <span class="invalid">E1/28/1</span> 

这里的诀窍是如果数字是由字符跟随的,它应该给出上面的输出和

如果输入具有以下内容

PD2.2/4, PD5.6/8/9

它应该将其转换为

er:#HKWBV1_SEC_2.2/P2.2/4 and er:#HKWBV1_SEC_5.6/P5.6/8/9

谢谢

4

1 回答 1

1
于 2013-10-25T16:10:02.053 回答