0
我正在使用XSl文件,其中我正在讀取xml節點中的值並創建另一個xml文件。以下是我想從中逐個讀取值節點的輸入xml的一部分。在xslt中獲取節點值一個接一個
輸入XML:
<Param>
<RoomsInvs>
<RoomInv>
<ProvisionalId Id="13-0000000007">13-0000000007</ProvisionalId>
</RoomInv>
<RoomInv>
<ProvisionalId Id="13-0000000008">13-0000000008</ProvisionalId>
</RoomInv>
</RoomsInvs>
<Rooms>
<Room NumberOfRooms="1" RoomId="TLC13-000005" Description="AC DEULEX" Twin="no" SupplierCode="RM" SupplierId="0" PropertyId="" ExtraBed="0" RateBasis="-4" Type="" Index="0">
<Rate Id="0" Currency="INR" Gross="4990.00" DisplayCurrency="INR" DisplayGross="4990.00" Net="4990.00" Tax="0" STax="" ExtraGuestCharge="0" AdultCount="2" AdultRate="1490.00" ChildCount="0" ChildRate=".00" Description="" Status="Available" AllocationDetails="-" SDisc="" SComm="" SRoomTotal="">
ieiorkmbjfgngjofmgfoikmfhkjg
</Rate>
</Room>
<Room NumberOfRooms="2" RoomId="TLC13-000005" Description="AC DEULEX" Twin="no" SupplierCode="RM" SupplierId="0" PropertyId="" ExtraBed="0" RateBasis="-4" Type="" Index="0">
<Rate Id="0" Currency="INR" Gross="4990.00" DisplayCurrency="INR" DisplayGross="4990.00" Net="4990.00" Tax="0" STax="" ExtraGuestCharge="0" AdultCount="2" AdultRate="1490.00" ChildCount="0" ChildRate=".00" Description="" Status="Available" AllocationDetails="-" SDisc="" SComm="" SRoomTotal="">
dbfbjsdbfjsdfbkjsdfbklnlnlsdf
</Rate>
</Room>
</Rooms>
<Param>
XSL應用:
<Rooms>
<xsl:apply-templates select="//Rooms/Room" >
<xsl:with-param name ="IdNo" select ="//RoomsInvs/RoomInv"></xsl:with-param>
</xsl:apply-templates>
</Rooms>
<xsl:template match="Room" >
<xsl:param name="IdNo"/>
<Room>
<tempID>
<xsl:value-of select="$IdNo[position()]/ProvisionalId"/>
</tempID>
<xsl:copy-of select="Rate"/>
</Room>
輸出獲取:
<Rooms>
<Room>
<tempID>13-0000000007</tempID>
<Rate Id="0" Currency="INR" Gross="4990.00" DisplayCurrency="INR" DisplayGross="4990.00" Net="4990.00" Tax="0" STax="" ExtraGuestCharge="0" AdultCount="2" AdultRate="1490.00" ChildCount="0" ChildRate=".00" Description="" Status="Available" AllocationDetails="-" SDisc="" SComm="" SRoomTotal="">
ieiorkmbjfgngjofmgfoikmfhkjg
</Rate>
</Room>
<Room>
<tempID>13-0000000007</tempID>
<Rate Id="0" Currency="INR" Gross="4990.00" DisplayCurrency="INR" DisplayGross="4990.00" Net="4990.00" Tax="0" STax="" ExtraGuestCharge="0" AdultCount="2" AdultRate="1490.00" ChildCount="0" ChildRate=".00" Description="" Status="Available" AllocationDetails="-" SDisc="" SComm="" SRoomTotal="">
dbfbjsdbfjsdfbkjsdfbklnlnlsdf
</Rate>
</Room>
</Rooms>
輸出我想:
<Rooms>
<Room>
<tempID>13-0000000007</tempID>
<Rate Id="0" Currency="INR" Gross="4990.00" DisplayCurrency="INR" DisplayGross="4990.00" Net="4990.00" Tax="0" STax="" ExtraGuestCharge="0" AdultCount="2" AdultRate="1490.00" ChildCount="0" ChildRate=".00" Description="" Status="Available" AllocationDetails="-" SDisc="" SComm="" SRoomTotal="">
ieiorkmbjfgngjofmgfoikmfhkjg
</Rate>
</Room>
<Room>
<tempID>13-0000000008</tempID>
<Rate Id="0" Currency="INR" Gross="4990.00" DisplayCurrency="INR" DisplayGross="4990.00" Net="4990.00" Tax="0" STax="" ExtraGuestCharge="0" AdultCount="2" AdultRate="1490.00" ChildCount="0" ChildRate=".00" Description="" Status="Available" AllocationDetails="-" SDisc="" SComm="" SRoomTotal="">
dbfbjsdbfjsdfbkjsdfbklnlnlsdf
</Rate>
</Room>
</Rooms>
您給出的解決方案是正確的,但我錯了。我沒有正確地提到我通過XSL所做的事情現在我已經編輯了它。 – Audy
好吧,但從你的例子中,我不知道你想要完成什麼。你能解釋一下嗎?或者我的示例解決了您的問題? – JLRishe
在這個問題中,我打電話給一個模板進行一些其他工作,這個模板給了我兩個節點,在這兩個節點中,我想要得到兩個「ProvisionalId」值,其中一個值是模板的第一個節點,另一個值是第二個節點的模板,但我正在爲模板中的節點獲得第一個值。所以我的問題是,我怎樣才能避免重複或我怎樣才能得到從模板返回的每個節點的單獨值? – Audy