嗨,需要一些帮助,以 XSLT 格式化为 element tag 创建一个序列编号。大多数是元素标签错过了一些数字,我需要以顺序格式获得输出,如下所示,通过将丢失的数字添加到 element tag 中,以座位标签。
在此方面的任何帮助都非常感谢。
。输入
<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>
以这种方式尝试:
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>