我想將XML文檔轉換爲另一個XML文檔。我嘗試了各種方法,其中沒有一種產生所需的目標XML文檔。使用查找的XLST
我有這樣一個假設輸入XML文檔:
<rows>
<row>
<name>ON</name>
<description/>
</row>
<row>
<name>NY</name>
<description/>
</row>
</rows>
我也有兩個查找:
<loc:locations>
<loc:location>
<loc:code>ON</loc:code>
<loc:value>Ontario</loc:value>
</loc:location>
<loc:location>
<loc:code>NY</loc:code>
<loc:value>New York</loc:value>
</loc:location>
</loc:locations>
<des:descriptions>
<des:description>
<des:code>ON</des:code>
<des:value>Ontario is a province in Canada</des:value>
</des:description>
<des:description>
<des:code>NY</des:code>
<des:value>New York is a state in the USA</des:value>
</des:description>
</des:descriptions>
我想輸入的XML轉化爲這個目標XML:
<places>
<place>
<name>Ontario</name>
<description>Ontario is a province in Canada</description>
</place>
<place>
<name>New York</name>
<description>New York is a state in the USA</description>
</place>
</places>
什麼是可以實現這一目標的XSLT?謝謝!
感謝empo,@greghmerrill。你的解決方案完美運作請注意,我必須從loc:locations和des:descriptions中刪除命名空間前綴。爲了克服「前綴未綁定」錯誤,我需要在兩個查找XML文檔的根上聲明xmlns屬性。 –