我需要創建一個新的xml結構,其中只存在一個映像版本,並且該版本應該是「a」,「16x9s」或「4x3s」 - 在這個優先事項。所以如果圖像版本「a」存在,那麼只有該圖像被選擇。如果它沒有,那麼尋找「16x9s」,最後是「4x3s」。 還需要一些其他節點(在下面的想要的結果代碼中大寫),而所有其他節點應該被丟棄。XSLT2:如何匹配基於優先級的單個節點
的XML(摘錄,它可以有很多較長或較短):
<?xml version="1.0" encoding="iso-8859-1"?>
<io>
<publication id="106125"/>
<related-images>
<image id="1112835">
<caption>null</caption>
<placement>FRONTPAGETITLE</placement>
<alignment>left</alignment>
<photographer></photographer>
<credit></credit>
<name>Some text</name>
<author></author>
<copyright></copyright>
<path>Image Root</path>
<description></description>
<alt-text></alt-text>
<image-version version-id="2060510" version-type="16x9s">
<url>/archive/01112/Thomas-Hicks-1_111283516x9s.jpg</url>
<width>649</width>
<height>365</height>
</image-version>
<image-version version-id="2060512" version-type="a">
<url>/archive/01112/Thomas-Hicks-16_11128353x4s.jpg</url>
<width>413</width>
<height>550</height>
</image-version>
<image-version version-id="2060513" version-type="4x3s">
<url>/archive/01112/Thomas-Hicks-16_11128354x3s.jpg</url>
<width>550</width>
<height>413</height>
</image-version>
</image>
<image id="1111482">
<caption>Some text</caption>
<placement>FRONTPAGELEADTEXT</placement>
<alignment>left</alignment>
<photographer></photographer>
<credit></credit>
<name>Some text</name>
<author></author>
<copyright></copyright>
<path>Image Root</path>
<description></description>
<alt-text></alt-text>
<image-version version-id="2060099" version-type="4x3s">
<url>/archive/01111/1904_tugofwar_11114824x3s.jpg</url>
<width>640</width>
<height>363</height>
</image-version>
<image-version version-id="2060075" version-type="f-tn">
<url>/archive/01111/1904_tugofwar_1111482f-tn.jpg</url>
<width>200</width>
<height>113</height>
</image-version>
<image-version version-id="2060094" version-type="y">
<url>/archive/01111/1904_tugofwar_1111482y.jpg</url>
<width>484</width>
<height>274</height>
</image-version>
</image>
<image id="1111465">
<caption>Some text</caption>
<placement>FRONTPAGELEADTEXT</placement>
<alignment>left</alignment>
<photographer>Getty Images</photographer>
<credit></credit>
<name>Some text</name>
<author></author>
<copyright></copyright>
<path>Image Root</path>
<description></description>
<alt-text></alt-text>
<image-version version-id="2058398" version-type="a">
<url>/archive/01111/1896_1111465a.jpg</url>
<width>1499</width>
<height>1103</height>
</image-version>
</image>
</related-images>
</io>
通緝結果:
<PTR:image>
<PTR:width>WIDTH OF IMAGE</PTR:width>
<PTR:height>HEIGHT OF IMAGE</PTR:height>
<PTR:src>IMAGE URL</PTR:src>
<PTR:title>
NAME
</PTR:title>
<PTR:description>
CAPTION
</PTR:description>
<PTR:author>
PHOTOGRAPHER
</PTR:author>
</PTR:image>
我已經嘗試了一些東西,像xsl:什麼時候,但是我的技術水平還不足以讓它工作。任何幫助將不勝感激。 乾杯。
你的輸入代碼段有三個'image'元素,[R esult只有一個。這是否意味着你只想從所有圖像中提取一個圖像?或者你想爲每個輸入的'image'元素提取符合條件的數據嗎? –
每個圖像節點在輸入xml中可以有多個圖像版本節點。 我想從每個圖像節點只提取一個圖像url,並且該圖像url應該來自image-versjon a或者如果a不存在,那麼16x9s或者如果這兩個都不存在,則4x3s。如果三者都不存在,則不應選擇圖像url。 – Shaidar
我現在看到我的結果代碼有點難以理解。該結果代碼就是我想要的輸入xml中的每個圖像節點。因此,多個節點,每個節點只有一個,其中源爲圖像版本a,16x9s或4x3s。 希望更清楚。 –
Shaidar