如何使用xslt创建增量数作为属性值

时间:2017-04-25 13:07:09

标签: xml xslt xslt-1.0 xslt-2.0

我想创建一个名为ID的属性,并希望将计数值分配给该

输入:

<section>
                <p>In reading and rounding negative numbers, the same rules apply. The negative number is preceded by a, –, or enclosed in parentheses. In business reports negative five may be written as <span class="inlineequation">
                        <m:math display="inline" alttext="" altimg="../images/ch01math3.png" altimg-width="17" altimg-height="12">
                            <m:mrow>
                                <m:mo>-</m:mo>
                                <m:mn>5</m:mn>
                            </m:mrow>
                        </m:math>
                    </span> or (5).</p>
                <div class="informalequation" id="P70010133850000000000000000114E1">
                    <m:math display="block" alttext="" altimg="../images/ch01math4.png" altimg-width="288" altimg-height="70">
                        <m:mrow>
                            <m:mtable columnalign="left">
                                <m:mtr columnalign="left">
                                    <m:mtd columnalign="left">
                                        <m:mrow>
                                            <m:mn>6</m:mn>
                                            <m:mo>+</m:mo>
                                            <m:mn>7</m:mn>
                                        </m:mrow>
                                    </m:mtd>
                                    <m:mtd columnalign="left">
                                        <m:mo>=</m:mo>
                                    </m:mtd>
                                    <m:mtd columnalign="left">
                                        <m:mrow>
                                            <m:mn>13</m:mn>
                                        </m:mrow>
                                    </m:mtd>
                                </m:mtr>
                                <m:mtr columnalign="left">
                                    <m:mtd columnalign="left">
                                        <m:mrow>
                                            <m:mtext>addends</m:mtext>
                                        </m:mrow>
                                    </m:mtd>
                                    <m:mtd columnalign="left">
                                        <m:mrow/>
                                    </m:mtd>
                                    <m:mtd columnalign="left">
                                        <m:mrow>
                                            <m:mtext>sum</m:mtext>
                                            <m:mo> </m:mo>
                                            <m:mtext>or</m:mtext>
                                            <m:mo> </m:mo>
                                            <m:mtext>total</m:mtext>
                                        </m:mrow>
                                    </m:mtd>
                                </m:mtr>
                            </m:mtable>
                        </m:mrow>
                    </m:math>
                </div>
            </section>

以上是输入

期望的输出:

<section>
                <p>In reading and rounding negative numbers, the same rules apply. The negative number is preceded by a, –, or enclosed in parentheses. In business reports negative five may be written as <span class="inlineequation">
                        <m:math id="0001" display="inline" alttext="" altimg="../images/ch01math3.png" altimg-width="17" altimg-height="12">
                            <m:mrow>
                                <m:mo>-</m:mo>
                                <m:mn>5</m:mn>
                            </m:mrow>
                        </m:math>
                    </span> or (5).</p>
                <div class="informalequation" id="P70010133850000000000000000114E1">
                    <m:math id="0002" display="block" alttext="" altimg="../images/ch01math4.png" altimg-width="288" altimg-height="70">
                        <m:mrow>
                            <m:mtable columnalign="left">
                                <m:mtr columnalign="left">
                                    <m:mtd columnalign="left">
                                        <m:mrow>
                                            <m:mn>6</m:mn>
                                            <m:mo>+</m:mo>
                                            <m:mn>7</m:mn>
                                        </m:mrow>
                                    </m:mtd>
                                    <m:mtd columnalign="left">
                                        <m:mo>=</m:mo>
                                    </m:mtd>
                                    <m:mtd columnalign="left">
                                        <m:mrow>
                                            <m:mn>13</m:mn>
                                        </m:mrow>
                                    </m:mtd>
                                </m:mtr>
                                <m:mtr columnalign="left">
                                    <m:mtd columnalign="left">
                                        <m:mrow>
                                            <m:mtext>addends</m:mtext>
                                        </m:mrow>
                                    </m:mtd>
                                    <m:mtd columnalign="left">
                                        <m:mrow/>
                                    </m:mtd>
                                    <m:mtd columnalign="left">
                                        <m:mrow>
                                            <m:mtext>sum</m:mtext>
                                            <m:mo> </m:mo>
                                            <m:mtext>or</m:mtext>
                                            <m:mo> </m:mo>
                                            <m:mtext>total</m:mtext>
                                        </m:mrow>
                                    </m:mtd>
                                </m:mtr>
                            </m:mtable>
                        </m:mrow>
                    </m:math>
                </div>
            </section>

你可以看到上面的例子中有一个&#34; id&#34; m:math标记中的属性,m:math标记可以出现在文件的任何位置

所以任何人都建议使用xslt方法来做到这一点

由于

0 个答案:

没有答案