Apply XSLT on XML to filter information based on tag match in same file



I am new to XML and XSLT, I want to filter some information from an XML file. Based on match on some tag values in the XML file.


This is my XML File as follows:



<?xml version="1.0" encoding="UTF-8"?>
<People>
<Person>
<required-tag1>some-information</required-tag1>
<required-tag2>some-information</required-tag2>
<tag3>not important info</tag3>
<tag4>not important info</tag4>
<first-name>Mike</first-name>
<last-name>Hewitt</last-name>
<licenses>
<license>
<number>1111</number>
<state>TX</state>
</license>
<license>
<number>2222</number>
<state>IL</state>
</license>
</licenses>
<appointments>
<appointment-info>
<licensed-states>
<state>TX</state>
</licensed-states>
</appointment-info>
</appointments>
</Person>
<Person>
<required-tag1>some-information</required-tag1>
<required-tag2>some-information</required-tag2>
<tag3>not important info</tag3>
<tag4>not important info</tag4>
<first-name>John</first-name>
<last-name>Jhonny</last-name>
<licenses>
<license>
<number>1111</number>
<state>TX</state>
</license>
<license>
<number>2222</number>
<state>IL</state>
</license>
<license>
<number>3333</number>
<state>NY</state>
</license>
</licenses>
<appointments>
<appointment-info>
<licensed-states>
<state>TX</state>
</licensed-states>
</appointment-info>
</appointments>
</Person>


What I want to basically do is that, if a Person is licensed in a state for example TX. And has appointment information in that state for example TX, filter that from licenses.


And the new xml should contain information of required tags. And only Licenses which didn't match with licenses in appointment licenses state.



<?xml version="1.0" encoding="UTF-8"?>
<People>
<Person>
<required-tag1>some-information</required-tag1>
<required-tag2>some-information</required-tag2>
<first-name>Mike</first-name>
<last-name>Hewitt</last-name>
<licenses>
<license>
<number>2222</number>
<state>IL</state>
</license>
</licenses>
</Person>
<Person>
<required-tag1>some-information</required-tag1>
<required-tag2>some-information</required-tag2>
<first-name>John</first-name>
<last-name>Jhonny</last-name>
<licenses>
<license>
<number>2222</number>
<state>IL</state>
</license>
<license>
<number>3333</number>
<state>NY</state>
</license>
</licenses>
</Person>


How to write an XSLT to filter this information.


No comments:

Post a Comment