Translate

Image of Android Wireless Application Development
Image of Linux Kernel Development (3rd Edition)
Image of Beginning Google Maps API 3
Image of Modern Operating Systems (3rd Edition)

XSLT Namespace Handling

This post assumes that you are familiar with XML, XSLT and XPath. It shows two methods to handle multiple default namespaces using XSLT1.0 and another method using XSLT2.0. Consider the following simple XML document: <Month xmlns="urn:murphy/ws/account/10/2007"> <LastPage>true</LastPage> <Accounts xmlns="urn:murphy/xml/account"> <Account> <AccountId>6289-F891T</AccountId> <Owner>6DS</Owner> <AccountType>Customer</AccountType> <Country>Philippines</Country> <SalesPerson>Joe Goon</SalesPerson> </Account> <Account> <AccountId>7142-J219F</AccountId> <Owner>IISC</Owner> <AccountType>Customer</AccountType> <Country>Canada</Country> <SalesPerson>Sarah Cergeo</SalesPerson> </Account> </Accounts> </Month> As you can see it has two namespaces, i.e urn:murphy/ws/account/10/2007 and urn:murphy/xml/account. The requirement is to transform this input document into the following output document using a stylesheet: <?xml version="1.0"?> <Month xmlns="urn:murphy/ws/account/10/2007"> <LastPage>true</LastPage> <Accounts xmlns="urn:murphy/xml/account"> <Account> <AccountId>6289-F891T</AccountId> <SalesPerson>Joe Goon</SalesPerson> </Account> <Account> <AccountId>7142-J219F</AccountId> <SalesPerson>Sarah

Manipulating XML Attributes using XSLT

Consider the following XML document called example.xml. As you can see, the document has two elements named sourcefield which contain multiple attributes. <source> <sourcefield businessname ="" datatype ="DATE" description ="" fieldnumber ="1" fieldproperty ="0" fieldtype ="ELEMITEM" hidden ="NO" keytype ="NOT A KEY" length ="19" level ="0" name ="BUSINESS_DATE" nullable ="NULL" occurs ="0" offset ="0" physicallength ="19" physicaloffset ="0" picturetext ="" precision ="19" scale ="0" usage_flags =""/> <sourcefield businessname ="JOHNSON" datatype ="DATE" description ="SHOEMAKER" fieldnumber ="1" fieldproperty ="1" fieldtype ="ELEMITEM" hidden ="NO" keytype ="NOT A KEY" length ="19" level ="3" name ="BUSINESS_DATE" nullable ="NULL" occurs ="0" offset ="0" physicallength ="19" physicaloffset