我有兩個XML,其中一個包含條件,另一個xml包含必須根據條件評估分配給結果XML的錯誤代碼列表。在xslt 2.0中合併了兩個xml
Conditions.xml
ErrorList.xml
<ErrorList>
<error>
<errorcode>1</errorcode>
<errordescription>UPDATE INDICATOR.</errordescription>
</error>
<error>
<errorcode>2</errorcode>
<errordescription>SHOULD NOT BE BLANK.</errordescription>
</error>
<error>
<errorcode>3</errorcode>
<errordescription>NOT IN LIST</errordescription>
</error>
<error>
<errorcode>4</errorcode>
<errordescription>PARSE ERROR.</errordescription>
</error>
輸入XML:
<a>
<c>
<UPDATE-IND>A</UPDATE-IND>
<DUP-OVERRIDE>B</DUP-OVERRIDE>
<TYPE-RECORD>R</TYPE-RECORD>
</c>
</a>
在XSLT生成的XML應該像
當條件1爲真(從Conditions.xml)第一組的從ErrorList.xml錯誤代碼的應生成的XML被顯示。同樣,對於所有滿足的條件,錯誤節點應顯示在我的最終XML中。
如何爲此編寫XSLT?我一直在嘗試使用document()函數,但無法弄清楚如何遍歷所有條件和錯誤代碼,以形成最終的XML。
注意:我與撒克遜-B XSLT 2.0嘗試這在我的Tibco BW作爲轉換引擎。
新邏輯:
而是將兩個XML的的,我想利用這既包含條件和錯誤代碼的單個XML的。
輸入XML保持不變。
條件XML:
<ns0:root xmlns:ns0 = "http://www.tibco.com/schemas/Validation.xsd">
<ns0:subElement1 ID = "id">
<ns0:subElement2 ID = "id">
<ns0:subElement3 ID = "id">
<ns0:subElement4 ID = "id">
<ns0:subElement5 cond = "1">
<ns0:conditions>1=1</ns0:conditions>
<ns0:errorcode>001</ns0:errorcode>
</ns0:subElement5>
<ns0:subElement5 cond = "2">
<ns0:conditions>2=2</ns0:conditions>
<ns0:errorcode>002</ns0:errorcode>
</ns0:subElement5>
<ns0:subElement5 cond = "3">
<ns0:conditions>3!=3</ns0:conditions>
<ns0:errorcode>003</ns0:errorcode>
</ns0:subElement5>
</ns0:subElement4>
</ns0:subElement3>
</ns0:subElement2>
</ns0:subElement1>
現在我想要得到的情況,對其進行評估並得到相同的XML相關的錯誤代碼。
注意: conditions.xml作爲輸入參數傳遞給XSLT。
你有什麼到目前爲止已經試過?這是你想要的嗎?如果Condition-1的值('1 = 1')爲true,那麼顯示'errorcode'的errordescription等於1?那麼''後面的部分表示應該使用哪個錯誤代碼? –
沒有' - '在這裏沒有意義。我將用撒克遜評估條件:evaluate()函數。如果第一個條件成立,則應顯示第一組錯誤節點,同樣應該評估XML中的所有條件。會有相同數量的條件和錯誤。 – Guru