I am looking for some help with XSLT to transform one xml file into another format.
The input xml file is below:
<PATIENTLIST ELAPSEDMS="234" >
<PATIENT ID="MGH000007">
<ADDRESS1>550 BREZHNEV ST</ADDRESS1>
<ADDRESS2></ADDRESS2>
<CITY>MOSCOW</CITY>
<STATE>MA</STATE>
<ZIP>02139</ZIP>
<COUNTRY ISO3166-1="USSR"></COUNTRY>
<DATEOFBIRTH>1934/04/10</DATEOFBIRTH>
<DAYPHONE>(617) 111-1111 </DAYPHONE>
<FIRSTNAME>TEST</FIRSTNAME>
<HOMEPHONE>(617) 111-1111</HOMEPHONE>
<LASTNAME>TEST MGH</LASTNAME>
<LIMITEDACCESS>False</LIMITEDACCESS>
<MARITALSTATUS>SINGLE</MARITALSTATUS>
<MEDICALRECORDNUMBERS>
<MEDICALRECORDNUMBER>
<SITE>BWH</SITE>
<STATUS>A</STATUS>
<VALUE>0000007</VALUE>
</MEDICALRECORDNUMBER>
<MEDICALRECORDNUMBER>
<SITE>BWI</SITE>
<STATUS>A</STATUS>
<VALUE>0000007</VALUE>
</MEDICALRECORDNUMBER>
<MEDICALRECORDNUMBER>
<SITE>MEEI</SITE>
<STATUS>A</STATUS>
<VALUE>0000007</VALUE>
</MEDICALRECORDNUMBER>
<MEDICALRECORDNUMBER>
<SITE>MGH</SITE>
<STATUS>A</STATUS>
<VALUE>0000007</VALUE>
</MEDICALRECORDNUMBER>
<MEDICALRECORDNUMBER>
<SITE>SHC</SITE>
<STATUS>A</STATUS>
<VALUE>0000007</VALUE>
</MEDICALRECORDNUMBER>
<MEDICALRECORDNUMBER>
<SITE>OLD #</SITE>
<STATUS>M</STATUS>
<VALUE>0000007</VALUE>
</MEDICALRECORDNUMBER>
</MEDICALRECORDNUMBERS>
<MIDDLEINITIAL>R</MIDDLEINITIAL>
<MOTHERSMAIDENNAME></MOTHERSMAIDENNAME>
<MRNR>0000007</MRNR>
<NAME>TEST MGH, TEST R</NAME>
<NAMESUFFIX></NAMESUFFIX>
<NAMEPREFIX></NAMEPREFIX>
<PRIMARYCAREPROVIDERID>512513</PRIMARYCAREPROVIDERID>
<PRIMARYLANGUAGE>ENGLISH</PRIMARYLANGUAGE>
<RACE CODE1="BLACK" CODE2="" FREETEXT="">BLACK</RACE>
<ETHNICITY CODE1="AFRICAN AMERICAN" CODE2="" FREETEXT="">AFRICAN AMERICAN</ETHNICITY>
<RELIGION>NO PREFERENCE</RELIGION>
<SEX>M</SEX>
<SSN></SSN>
<UID>101662537</UID>
<VETERAN>NO</VETERAN>
</PATIENT>
</PATIENTLIST>
The output file needs to look like:
<?xml version="1.0" encoding="utf-8" ?>
<eCliPSEDataIntegrationServiceRequest xmlns="http://iocent.com/eCliPSEDataIntegrationServiceRequest.xsd">
<PatientIdentifierRecord MedicalRecordNumber="MGH000007" LastName="Person" FirstName="Test" MiddleInitial="A" DateOfBirth="04/10/1934" Operation="Add" OverwriteExistingData="true" />
<PatientDataRecord MedicalRecordNumber="MGH000007" ParameterName="Gender" ParameterValue="2" TimeStamp="8/30/2011" Operation="Add" OverwriteExistingData="true" />
<PatientDataRecord MedicalRecordNumber="MGH000007" ParameterName="Race" ParameterValue="1" TimeStamp="8/30/2011" Operation="Add" OverwriteExistingData="true" />
</eCliPSEDataIntegrationServiceRequest>
So I am looking to pull out the
Patient ID and use it as the MedicalRecordNumber= value
DATEOFBIRTH node as the DateOfBirth value - with format changed from YYYY/MM/DD to MM/DD/YYYY
FIRSTNAME node becomes value for FirstName
LASTNAME node becomes value for LastName
MIDDLEINITIAL node becomes value for MiddleInitial
SEX node becomes value for Gender Male=1, Female=2
RACE node becomes Value for Race - based on a lookup table (Caucasian=1,Afican American=2, etc.) -
So I need to pull out these values, get the format changed, in some cases do a table-like translation (for gender and race), and write the file out in the new format.
I am limited to XSLT 1.0
I am very new to XSLT and so any help would be greatly appreciated!!!
thanks!
Just a few hints.
Use AVT syntax to simplify your code. Example:
For line feed, use code from ISO-8859-1 character set:
For date-time see this topic and check your parser documentation.
If you need to change date format, use
substring()
andconcat()
function. Check this similar topic.It seems that you are using line feed to indent your code. For this job you have a proper instruction (which might be supported depending on your parser):
Based on feedback - I am updating my solution and posting here
Thank you for the feedback and suggestions.
This version handles case conversion/comparison as well as formatting the bday in a format that I needed.
I like the AVT syntax to simplify the code and the to remove the "manual formatting" that I was doing - thanks for those tips!
I appreciate the start that I received above. I am posting the xslt that I came up with to solve my problem below:
I am still working on a solution to get the current date. Options I have looked at - passing in as parameter - writing a script function to get the current date
Also, I am not sure yet if I need to change the format of the date from YYYY/MM/DD to MM/DD/YYYY.
If anyone has some suggestions on the two topics above, they would be welcomed.
thanks
this should get you started down the right path:
You will probably need some hard coded
<xsl:if test="SEX='MALE'">1</xsl:if>
statements to do the "enum" switching