在XML嵌套的元素我有一個平坦的XML看起來像這樣:無法創建使用XLST
<objectDataList>
<objectData>
<equipment>
<name>Chassis-One</name>
<type>Chassis</type>
</equipment>
</objectData>
<objectData>
<equipment>
<name>Shelf-One</name>
<type>Shelf</type>
</equipment>
</objectData>
<objectData>
<equipment>
<name>Shelf-Two</name>
<type>Shelf</type>
</equipment>
</objectData>
<objectData>
<equipment>
<name>Slot-One</name>
<type>Slot</type>
</equipment>
</objectData>
如何創建一個XSL,將改變我的XML到另一個XML,看起來像這樣的:
<equipments>
<object>
<name>Chassis-One</name>
<object>
<name>Shelf-One</name>
<object>
<name>Slot-One</name>
</object>
</object>
</object>
這就像在一個機箱中,有2架,並在貨架一個,有槽-One ..
我中途試過,但我想不出如何使嵌套的元素:
<xsl:template match="/response">
<equipments>
<object>
<xsl:apply-templates select="objectData"/>
</object>
</equipments>
<xsl:template match="objectData/equipment[type='Chassis']">
<name><xsl:value-of select="equipment/name"/></name>
<!-- Now I want to find the shelf according to the chassis name -->
<xsl:call-template name="find-shelf-according-to-chasis-name">
<xsl:with-param name="chassisName" select="equipment/name"/>
</xsl:call-template>
</xsl:template>
我希望有人能擺脫一些光
謝謝你提前
除了姓名約定,應該如何腳本上的節點之間的父子關係決定? – rsp 2011-06-08 08:15:28
基於 =「%-One」..基本上如果貨架名稱是Shelf-One,那麼它將屬於Chassis-One ..並且如果插槽名稱是SLot-One,那麼它將屬於貨架-One .. –
rainingDay
2011-06-08 08:22:41
在您的示例中,您將貨架二放置在機箱一之下。如果輸入中缺少Chassic-Two,它是否應該在輸出中? – rsp 2011-06-08 08:43:23