XSLT新手,但在這裏的帖子中學到了很多東西。但是,我陷入了一個問題。XSLT嵌套查找
我正在使用XSLT爲設備安裝創建報告。輸入XML看起來是這樣的:
<DeviceTypes>
<DeviceInfo Model="51473">
<Channels>
<ChannelInfo ChannelId="1" IsImplemented="false" SampRateHardware="448" />
<ChannelInfo ChannelId="2" IsImplemented="true" SampRateHardware="224" />
</Channels>
</DeviceInfo>
<DeviceInfo Model="51474">
<Channels>
<ChannelInfo ChannelId="1" IsImplemented="true" SampRateHardware="448" />
<ChannelInfo ChannelId="2" IsImplemented="true" SampRateHardware="224" />
</Channels>
</DeviceInfo>
</DeviceTypes>
<Installation>
<InstalledDevice Serial="597657" Model="51473">
<Channels>
<InstalledChannel ChannelId="1" Name="foo" />
<InstalledChannel ChannelId="2" Name="bar" />
</Channels>
</InstalledDevice>
</Installation>
我只想過程中,如果相應的ChannelInfo有一個「IsImplemented」設置爲true InstallChannel節點。通過「對應」我的意思是我正在尋找具有相同的ChannelId和父節點下相同的模型的ChannelInfo。請注意,具有相同ChannelId的通道可能具有不同的IsImplemented值,具體取決於它們所處的設備。
我一直在使用和key()函數來成功查找,但這種嵌套查找讓我難堪。
感謝,
-Mat
謝謝。我認爲你很接近。同樣,訣竅是可能有多個ChannelInfo在不同的DeviceInfo下具有相同的ChannelId,並且它們不一定都具有相同的IsImplemented。我會更新示例來說明這一點。 – mek363 2012-04-02 19:13:31
沒問題,相同的一般概念仍然適用,你只需要在樹上開一個更高的點,並且你的xpath變得有點複雜。 (我更新了我的答案)。 – javram 2012-04-02 19:29:03
我認爲現在的問題是,您的變量「channelId」將抓取第一個InstalledChannel,但可能會有多個。我試圖保持我的例子簡單。我會再次更新。謝謝。 – mek363 2012-04-02 21:02:33