我有一個XML文檔通過Web服務返回給我。如何使用XLST從XML中刪除某些屬性
<Kronos_WFC encoding="ASCII" version="1.0" WFCVersion="6.1" TimeStamp="01/5/2011 8:38AM">
<Response Status="Success" Timeout="1800" PersonKey="-1" Object="System" Username="1" Action="Logon" PersonNumber="1">
</Response>
<Response Status="Success" action="Load">
<ScheduleGroup ScheduleGroupName="SomeName" AllowsInheritance="false" AllowContract="false" IsEmploymentTerm="false" />
<ScheduleGroup ScheduleGroupName="GreatName" AllowsInheritance="true" AllowContract="false" IsEmploymentTerm="false" />
<ScheduleGroup ScheduleGroupName="BestName" AllowsInheritance="true" AllowContract="false" IsEmploymentTerm="false" />
</Response>
<Response Status="Success" Object="System" Action="Logoff">
</Response>
</Kronos_WFC>
的問題是我把成果轉化爲有關本產品(xsd2code
)XSD模式生成的業務對象。該產品在架構沒有爲屬性(Response
):
- 超時
- PersonKey
- 對象
- 用戶名
我想做到以下幾點:
- 刪除上述屬性
- 將所有其他屬性轉換成元素,包括所有的孩子,和孩子們的兒童等
我如何做到這一點使用XLST。使用Regex刪除不需要的屬性會更簡單嗎?
使用XSLT生成您需要的XML。要開始看到http://www.w3schools.com/xsl – nickytonline 2011-05-30 02:16:36
好問題,+1。查看我的答案,獲得完整,簡短的解決方案和解釋。這個解決方案非常優雅,因爲它使用了最基礎和最強大的XSLT設計模式 - 重寫身份規則/模板。 – 2011-05-30 02:56:08
美麗的+1 Thankyou – Jeremy 2011-05-30 03:57:26