-2
我正在尋找一種方法來使用xslt從xml文件中替換字段的值。除了命名空間前綴以外,一切都很好。在下面的源文件中,我想更改密碼元素值。如何用XSLT替換元素通過保留名稱空間前綴
<?xml version="1.0" encoding="utf-8"?>
<ns0:MYXML xmlns:ns0="http://www.me.com/myxml" xmlns="http://www.me.com/myxml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns0:Header>
<ns0:Infromation>
<ns0:From>
<ns0:Credential>
<ns0:User>jeff</ns0:User>
<Password xmlns="">OLD VALUE</Password>
</ns0:Credential>
</ns0:From>
</ns0:Infromation>
<ns0:Misc>
<ns0:ID>1002</ns0:ID>
<ns0:Timestamp>2012-01-16T09:23:33</ns0:Timestamp>
<ns0:Type>unknown</ns0:Type>
</ns0:Misc>
<ns0:State>
<ns0:ConversationId>d66d9304-9025-a580-e111-5640bf36560d</ns0:ConversationId>
</ns0:State>
</ns0:Header>
</ns0:MYXML>
這裏是我的結果:
<?xml version="1.0" encoding="utf-8"?>
<ns0:MYXML xmlns:ns0="http://www.me.com/myxml" xmlns="http://www.me.com/myxml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns0:Header>
<ns0:Infromation>
<ns0:From>
<ns0:Credential>
<ns0:User>jeff</ns0:User>
<Password xmlns="">New Value</Password>
</ns0:Credential>
</ns0:From>
</ns0:Infromation>
<ns0:Misc>
<ns0:ID>1002</ns0:ID>
<ns0:Timestamp>2012-01-16T09:23:33</ns0:Timestamp>
<ns0:Type>unknown</ns0:Type>
</ns0:Misc>
<ns0:State>
<ns0:ConversationId>d66d9304-9025-a580-e111-5640bf36560d</ns0:ConversationId>
</ns0:State>
</ns0:Header>
</ns0:MYXML>
這就是今天的XSLT代碼,我使用的轉型:
<?xml version="1.0" encoding="utf-8"?>
<ns0:MYXML xmlns:ns0="http://www.me.com/myxml" xmlns="http://www.me.com/myxml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns0:Header>
<ns0:Infromation>
<ns0:From>
<ns0:Credential>
<ns0:User>jeff</ns0:User>
<Password xmlns="">New Value</Password>
</ns0:Credential>
</ns0:From>
</ns0:Infromation>
<ns0:Misc>
<ns0:ID>1002</ns0:ID>
<ns0:Timestamp>2012-01-16T09:23:33</ns0:Timestamp>
<ns0:Type>unknown</ns0:Type>
</ns0:Misc>
<ns0:State>
<ns0:ConversationId>d66d9304-9025-a580-e111-5640bf36560d</ns0:ConversationId>
</ns0:State>
</ns0:Header>
</ns0:MYXML>
我試圖用 「{名()}」 爲元素名稱,但這會引發該名稱空間不存在的異常。
任何幫助,非常感謝!
重複問:請參見本:: http://stackoverflow.com/questions/3147876/how-to-preserve-xml-namespace-in- xslt-output –
你還沒有說出你想要的輸出。我們唯一知道的關於你想要的輸出的是,它不是你實際得到的輸出。回答問題。 –