given xml :
<transetx220a1>
<trantypeenum>ST01834</trantypeenum>
<trantypeval>834</trantypeval>
<controlnumber>745029</controlnumber>
<tranversionreleaseenum>v005010X220A1</tranversionreleaseenum>
<tranversionreleaseval>005010X220A1</tranversionreleaseval>
<segmentcount>32</segmentcount>
<bgn>
<purposecodeenum>BGN0100</purposecodeenum>
<purposecodeval>00</purposecodeval>
<referenceid>060743616745029</referenceid>
<creationdate>20160506</creationdate>
<creationtime>0744</creationtime>
<timezoneenum>CT</timezoneenum>
<timezoneval>CT</timezoneval>
<actioncodeenum>RX</actioncodeenum>
<actioncodeval>RX</actioncodeval>
</bgn>
<fileeffdate>
<datetimeperiod>
<dtptypeenum>DTP303</dtptypeenum>
<dtptypeval>303</dtptypeval>
<formatenum>D8</formatenum>
<formatval>D8</formatval>
<value>20160506</value>
</datetimeperiod>
</fileeffdate>
<qtytrancontrols />
<sponsorname>
<partyidenum>P5</partyidenum>
<partyidval>P5</partyidval>
<entityname>Casey McCasland</entityname>
<partyidqualenum>FI</partyidqualenum>
<partyidqualval>FI</partyidqualval>
<identifier>999999999</identifier>
</sponsorname>
<payername>
<partyidenum>IN</partyidenum>
<partyidval>IN</partyidval>
<entityname>New Mexico Health Connections</entityname>
<partyidqualenum>FI</partyidqualenum>
<partyidqualval>FI</partyidqualval>
<identifier>453416923</identifier>
</payername>
<tpa_brokername />
<enrollment>
<eligx220a1>
<ins>
<memberindenum>Y</memberindenum>
<memberindval>Y</memberindval>
<indrelenum>INS0218</indrelenum>
<indrelval>18</indrelval>
<maintenancetypeenum>INS03030</maintenancetypeenum>
<maintenancetypeval>030</maintenancetypeval>
<benefitstatusenum>A</benefitstatusenum>
<benefitstatusval>A</benefitstatusval>
<employmentstatusenum>AC</employmentstatusenum>
<employmentstatusval>AC</employmentstatusval>
</ins>
<subscribernumber>
<reftypeenum>REF010F</reftypeenum>
<reftypeval>0F</reftypeval>
<value>P700060195</value>
</subscribernumber>
<policynumber>
<reftypeenum>REF011L</reftypeenum>
<reftypeval>1L</reftypeval>
<value>P900010001</value>
</policynumber>
<supplementalid>
<referenceid>
<reftypeenum>REF0117</reftypeenum>
<reftypeval>17</reftypeval>
<value>001</value>
</referenceid>
</supplementalid>
<memberleveldates>
<datetimeperiod>
<dtptypeenum>DTP356</dtptypeenum>
<dtptypeval>356</dtptypeval>
<formatenum>D8</formatenum>
<formatval>D8</formatval>
<value>20160201</value>
</datetimeperiod>
</memberleveldates>
<memb>
<affiliatename>
<entityidenum>IL</entityidenum>
<entityidval>IL</entityidval>
<entitytypeenum>NM1021</entitytypeenum>
<entitytypeval>1</entitytypeval>
<lastname>Mcsasasas</lastname>
<firstname>Casss</firstname>
<idqualifierenum>NM10834</idqualifierenum>
<idqualifierval>34</idqualifierval>
<identifier>999999999</identifier>
</affiliatename>
<affiliateaddress>
<locationcodeenum>CY</locationcodeenum>
<locationcodeval>CY</locationcodeval>
<locationcodeidentifier>CURRY</locationcodeidentifier>
<addrline1>149 sssssss AVE</addrline1>
<city>CLOVIS</city>
<state>NM</state>
<zip>88101</zip>
</affiliateaddress>
<affiliatecontact>
<contact>
<comm>
<communication>
<commtypeenum>HP</commtypeenum>
<commtypeval>HP</commtypeval>
<value>5121212482</value>
</communication>
<communication>
<commtypeenum>EM</commtypeenum>
<commtypeval>EM</commtypeval>
<value>tfsasasl@farsasassant.com</value>
</communication>
</comm>
<functioncodeenum>IP</functioncodeenum>
<functioncodeval>IP</functioncodeval>
</contact>
</affiliatecontact>
</memb>
<membdmg>
<birthdateformatenum>D8</birthdateformatenum>
<birthdateformatval>D8</birthdateformatval>
<birthdate>19611111</birthdate>
<genderenum>M</genderenum>
<genderval>M</genderval>
<maritalstatusenum>B</maritalstatusenum>
<maritalstatusval>B</maritalstatusval>
</membdmg>
<empclass />
<amtpolicy />
<hlh>
<healthcodeenum>N</healthcodeenum>
<healthcodeval>N</healthcodeval>
</hlh>
<lui />
<school />
<responsibleperson />
<dsb />
<healthcov>
<healthcoverage>
<hd>
<maintenancetypecodeenum>HD01030</maintenancetypecodeenum>
<maintenancetypecodeval>030</maintenancetypecodeval>
<insurancelineenum>HLT</insurancelineenum>
<insurancelineval>HLT</insurancelineval>
<coveragelevelenum>EMP</coveragelevelenum>
<coveragelevelval>EMP</coveragelevelval>
</hd>
<dtpcoverage>
<datetimeperiod>
<dtptypeenum>DTP348</dtptypeenum>
<dtptypeval>348</dtptypeval>
<formatenum>D8</formatenum>
<formatval>D8</formatval>
<value>20160201</value>
</datetimeperiod>
</dtpcoverage>
<policynumber>
<referenceid>
<reftypeenum>CE</reftypeenum>
<reftypeval>CE</reftypeval>
<value>93091NM001001000</value>
</referenceid>
</policynumber>
<provider>
<memberpcp>
<sequentialnumber>1</sequentialnumber>
<provider>
<affiliatename>
<entityidenum>P3</entityidenum>
<entityidval>P3</entityidval>
<entitytypeenum>NM1021</entitytypeenum>
<entitytypeval>1</entitytypeval>
<idqualifierenum>XX</idqualifierenum>
<idqualifierval>XX</idqualifierval>
<identifier>1437296522</identifier>
</affiliatename>
<affiliateaddress>
<addrline1>702 N 13th St</addrline1>
<city>Artesia</city>
<state>NM</state>
<zip>88210</zip>
</affiliateaddress>
</provider>
</memberpcp>
</provider>
</healthcoverage>
</healthcov>
<lsloopheader>Item2700</lsloopheader>
<report>
<memberreport>
<sequentialnumber>1</sequentialnumber>
<reportcategory>
<partyidenum>N10175</partyidenum>
<partyidval>75</partyidval>
<entityname>PRE AMT TOT</entityname>
</reportcategory>
<refcategory>
<reftypeenum>REF019X</reftypeenum>
<reftypeval>9X</reftypeval>
<value>414.31</value>
</refcategory>
<reportcategorydate>
<dtptypeenum>DTP007</dtptypeenum>
<dtptypeval>007</dtptypeval>
<formatenum>D8</formatenum>
<formatval>D8</formatval>
<value>20150101</value>
</reportcategorydate>
</memberreport>
</report>
<lelooptrailer>Item2700</lelooptrailer>
</eligx220a1>
</enrollment>
</transetx220a1>
尝试过XSL代码:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="/transetx220a1/sponsorname/entityname">
<div style="font-weight:bold;color:white;background-color: brown">
<xsl:value-of select="../entityname"/>
</div>
<div>
<div>
<span style="font-weight:bold">Date Format:</span>
<xsl:if test="contains(../../enrollment/eligx220a1/membdmg/birthdateformatval, 'D8')">
Date Expressed in Format CCYYMMDD
</xsl:if>
</div>
<div>
<span style="font-weight:bold">Date of Birth:</span>
<xsl:value-of select="../../enrollment/eligx220a1/membdmg/birthdate"/>
</div>
<div>
<span style="font-weight:bold">Gender:</span>
<xsl:choose>
<xsl:when test="contains(../../enrollment/eligx220a1/membdmg/genderval, 'M')">
Male
</xsl:when>
<xsl:otherwise>
Female
</xsl:otherwise>
</xsl:choose>
</div>
<div>
<span style="font-weight:bold">Relationship:</span>
<xsl:if test="contains(../../enrollment/eligx220a1/membdmg/maritalstatusval, 'B')">
Registered Domestic Partner
</xsl:if>
<xsl:if test="contains(../../enrollment/eligx220a1/membdmg/maritalstatusval, 'D')">
Divorced
</xsl:if>
<xsl:if test="contains(../../enrollment/eligx220a1/membdmg/maritalstatusval, 'I')">
Single
</xsl:if>
<xsl:if test="contains(../../enrollment/eligx220a1/membdmg/maritalstatusval, 'M')">
Married
</xsl:if>
<xsl:if test="contains(../../enrollment/eligx220a1/membdmg/maritalstatusval, 'S')">
Seperated
</xsl:if>
<xsl:if test="contains(../../enrollment/eligx220a1/membdmg/maritalstatusval, 'U')">
Unmarried
</xsl:if>
<xsl:if test="contains(../../enrollment/eligx220a1/membdmg/maritalstatusval, 'W')">
Widowed
</xsl:if>
<xsl:if test="contains(../../enrollment/eligx220a1/membdmg/maritalstatusval, 'X')">
Legally Seperated
</xsl:if>
</div>
</div>
<div style="font-weight:bold;">
<xsl:value-of select="../../enrollment/eligx220a1/memb/affiliatecontact/contact/comm"/>
</div>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
给出的输出:
<html>
<body>
<div style="font-weight:bold;color:white;background-color: brown">Casey McCasland</div>
<div>
<div><span style="font-weight:bold">Date Format:</span>
Date Expressed in Format CCYYMMDD
</div>
<div><span style="font-weight:bold">Date of Birth:</span>19611111
</div>
<div><span style="font-weight:bold">Gender:</span>
Male
</div>
<div><span style="font-weight:bold">Relationship:</span>
Registered Domestic Partner
</div>
</div>
<div style="font-weight:bold;">
HP
HP
5121212482
EM
EM
tfsasasl@farsasassant.com
</div>
</body>
</html>
期望的输出:
<html>
<body>
<div style="font-weight:bold;color:white;background-color: brown">Casey McCasland</div>
<div>
<div><span style="font-weight:bold">Date Format:</span>
Date Expressed in Format CCYYMMDD
</div>
<div><span style="font-weight:bold">Date of Birth:</span>19611111
</div>
<div><span style="font-weight:bold">Gender:</span>
Male
</div>
<div><span style="font-weight:bold">Relationship:</span>
Registered Domestic Partner
</div>
</div>
<div style="font-weight:bold;">
<div>
HP
HP
5121212482
</div>
<div>
EM
EM
tfsasasl@farsasassant.com
</div>
</div>
</body>
</html>
我想在不同的div中显示comm值,并在不同的行中显示它。任何帮助表示赞赏。我正在尝试使用XML代码并嵌入XSLT代码并将其转换为HTML代码并将其显示在页面中。这背后的基本思想是使用赞助商名称的Xpath“Casey Mccasland”以单独的方式显示所有通信细节。
答案 0 :(得分:0)
您的comm
元素如下所示:
<comm>
<communication>
<commtypeenum>HP</commtypeenum>
<commtypeval>HP</commtypeval>
<value>5121212482</value>
</communication>
<communication>
<commtypeenum>EM</commtypeenum>
<commtypeval>EM</commtypeval>
<value>tfsasasl@farsasassant.com</value>
</communication>
</comm>
但要显示它,你就是这样做的:
<xsl:value-of select="../../enrollment/eligx220a1/memb/affiliatecontact/contact/comm"/>
这只输出所有后代节点的连接文本值,而不进行格式化。您确实需要单独选择communication
元素,为每个元素输出div
,然后输出子元素。
尝试此操作而不是执行xsl:value-of
<div style="font-weight:bold;">
<xsl:for-each select="../../enrollment/eligx220a1/memb/affiliatecontact/contact/comm/communication">
<div>
<xsl:for-each select="*">
<xsl:value-of select="." /><br />
</xsl:for-each>
</div>
</xsl:for-each>
</div>