XSLT 1.0中的序列编号

时间:2017-09-05 17:39:29

标签: xslt xslt-1.0 xslt-grouping

您需要一些 XSLT 格式的帮助才能为元素标记创建序列号。大多数元素标记错过了序列中的一些数字,我需要按顺序格式获得输出,如下所示,在 元素标记中添加缺少的数字>座位标签

非常感谢任何帮助,提前谢谢。

输入

<book>
<Seat>
    <seatNumber>12A</seatNumber>
    <Element>1</Element>
    <Number>1</Number>
</Seat>
<Seat>
    <seatNumber>12B</seatNumber>
    <Element>3</Element>
    <Number>1</Number>
</Seat>
<Seat>
    <seatNumber>12C</seatNumber>
    <Element>4</Element>
    <Number>1</Number>
</Seat>
<Seat>
    <seatNumber>12D</seatNumber>
    <Element>5</Element>
    <Number>1</Number>
</Seat>
<Seat>
    <seatNumber>12E</seatNumber>
    <Element>7</Element>
    <Number>1</Number>
</Seat>
</book>

输出

<book>
<Seat>
    <seatNumber>12A</seatNumber>
    <Element>1</Element>
    <Number>1</Number>
</Seat>
<Seat>
    <seatNumber>12B</seatNumber>
    <Element>2</Element>
    <Number>1</Number>
</Seat>
<Seat>
    <seatNumber>12C</seatNumber>
    <Element>3</Element>
    <Number>1</Number>
</Seat>
<Seat>
    <seatNumber>12D</seatNumber>
    <Element>4</Element>
    <Number>1</Number>
</Seat>
<Seat>
    <seatNumber>12E</seatNumber>
    <Element>5</Element>
    <Number>1</Number>
</Seat>
</book>

1 个答案:

答案 0 :(得分:1)

以这种方式尝试:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="Element">
    <xsl:copy>
        <xsl:number count="Seat"/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>