2017-09-05 76 views
0

您需要一些幫助XSLT格式化用於創建序列號元素標記。主要是元素標籤錯過了一些數字的順序,我需要得到一個順序格式的輸出,如下所示,通過添加缺失的數字元素標籤在相同的序列座位標籤XSLT 1.0中的序列號

任何幫助,在此非常感謝,提前感謝。

輸入

<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

試試這樣說:

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> 
+0

Thanx這工作..有沒有其他方式出模板使用? –

+0

您對使用模板有何反對? –

+0

我需要在xslt中使用它,它還有其他操作,並且需要在BPEL中實現 –