gpt4 book ai didi

xml - XSLT 将 xml 转换为 xml 提取特定值并映射到新格式

转载 作者:行者123 更新时间:2023-12-03 16:21:57 24 4
gpt4 key购买 nike

我正在寻找有关 XSLT 的帮助,以将一个 xml 文件转换为另一种格式。

输入的xml文件如下:

<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>

输出文件需要如下所示:
<?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>

所以我想拔出

患者 ID 并将其用作 MedicalRecordNumber= 值

DATEOFBIRTH 节点作为 DateOfBirth 值 - 格式从 YYYY/MM/DD 更改为 MM/DD/YYYY

FIRSTNAME 节点成为 FirstName 的值

LASTNAME 节点成为 LastName 的值

MIDDLEINITIAL 节点成为 MiddleInitial 的值

SEX 节点变为 Gender Male=1, Female=2 的值

RACE 节点变为 Value for Race - 基于查找表(高加索人 = 1,非裔美国人 = 2 等) -

所以我需要提取这些值,更改格式,在某些情况下进行类似表格的翻译(针对性别和种族),然后以新格式写出文件。

我仅限于 XSLT 1.0

我对 XSLT 很陌生,因此将不胜感激任何帮助!!!

谢谢!

最佳答案

我很感激我在上面收到的开始。我在下面发布了我想出的解决问题的 xslt:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:variable name='newline'><xsl:text>
</xsl:text>
</xsl:variable>

<xsl:variable name='MRN'>
<xsl:value-of select="PATIENTLIST/PATIENT/@ID"/>
</xsl:variable>

<xsl:variable name='Gender'>
<xsl:if test="PATIENTLIST/PATIENT/SEX='M'">1</xsl:if>
<xsl:if test="PATIENTLIST/PATIENT/SEX='F'">2</xsl:if>
</xsl:variable>

<xsl:variable name='RaceIn'>
<xsl:value-of select="PATIENTLIST/PATIENT/RACE"/>
</xsl:variable>

<xsl:variable name='Race'>
<xsl:choose>
<xsl:when test="$RaceIn='WHITE'">1</xsl:when>
<xsl:when test="$RaceIn='BLACK'">2</xsl:when>
<xsl:when test="$RaceIn='HISPANIC'">3</xsl:when>
<xsl:when test="$RaceIn='ASIAN'">4</xsl:when>
<xsl:when test="$RaceIn='NATIVE AMERICAN'">5</xsl:when>
<xsl:when test="$RaceIn='INDIAN'">5</xsl:when>
<xsl:otherwise>7</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:variable name='CurrDate'>
<xsl:value-of select="'MM/DD/YYY'"/>
</xsl:variable>

<xsl:variable name='Operation'>
<xsl:value-of select="'Add'"/>
</xsl:variable>

<xsl:variable name='Overwrite'>
<xsl:value-of select="'true'"/>
</xsl:variable>




<xsl:template match="/">
<xsl:text>
</xsl:text>
<eCliPSEDataIntegrationServiceRequest >
<xsl:text>
</xsl:text>
<PatientIdentifierRecord>
<xsl:attribute name="MedicalRecordNumber">
<xsl:value-of select="$MRN"/>
</xsl:attribute>
<xsl:attribute name="LastName">
<xsl:value-of select="PATIENTLIST/PATIENT/LASTNAME"/>
</xsl:attribute>
<xsl:attribute name="FirstName">
<xsl:value-of select="PATIENTLIST/PATIENT/FIRSTNAME"/>
</xsl:attribute>
<xsl:attribute name="MiddleInitial">
<xsl:value-of select="PATIENTLIST/PATIENT/MIDDLEINITIAL"/>
</xsl:attribute>
<xsl:attribute name="DateOfBirth">
<xsl:value-of select="PATIENTLIST/PATIENT/DATEOFBIRTH"/> <!-- do we need to change the date format?-->
</xsl:attribute>
<xsl:attribute name="Operation">
<xsl:value-of select="$Operation"/>
</xsl:attribute>
<xsl:attribute name="OverwriteExistingData">
<xsl:value-of select="$Overwrite"/>
</xsl:attribute>
</PatientIdentifierRecord>
<xsl:text>
</xsl:text>
<PatientDataRecord>
<xsl:attribute name="MedicalRecordNumber">
<xsl:value-of select="$MRN"/>
</xsl:attribute>
<xsl:attribute name="ParameterName">
<xsl:value-of select="'Gender'"/>
</xsl:attribute>
<xsl:attribute name="ParameterValue">
<xsl:value-of select="$Gender"/>
</xsl:attribute>
<xsl:attribute name="Timestamp">
<xsl:value-of select="$CurrDate"/>
</xsl:attribute>
<xsl:attribute name="Operation">
<xsl:value-of select="$Operation"/>
</xsl:attribute>
<xsl:attribute name="OverwriteExistingData">
<xsl:value-of select="$Overwrite"/>
</xsl:attribute>
</PatientDataRecord>
<xsl:text>
</xsl:text>
<PatientDataRecord>
<xsl:attribute name="MedicalRecordNumber">
<xsl:value-of select="$MRN"/>
</xsl:attribute>
<xsl:attribute name="ParameterName">
<xsl:value-of select="'Race'"/>
</xsl:attribute>
<xsl:attribute name="ParameterValue">
<xsl:value-of select="$Race"/> <!-- this needs to be transformed based on race table and race_7_groups parameter -->
</xsl:attribute>
<xsl:attribute name="Timestamp">
<xsl:value-of select="$CurrDate"/> <!-- how do i get the current date?-->
</xsl:attribute>
<xsl:attribute name="Operation">
<xsl:value-of select="$Operation"/>
</xsl:attribute>
<xsl:attribute name="OverwriteExistingData">
<xsl:value-of select="$Overwrite"/>
</xsl:attribute>
</PatientDataRecord>
<xsl:text>
</xsl:text>
</eCliPSEDataIntegrationServiceRequest>
</xsl:template>
</xsl:stylesheet>

我仍在研究获取当前日期的解决方案。我看过的选项
- 作为参数传入
- 编写脚本函数来获取当前日期

另外,我不确定是否需要将日期格式从 YYYY/MM/DD 更改为 MM/DD/YYYY。

如果有人对上述两个主题有一些建议,他们将受到欢迎。

谢谢

关于xml - XSLT 将 xml 转换为 xml 提取特定值并映射到新格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7250503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com