使用值创建递归元素

时间:2012-11-02 05:06:13

标签: xslt

我正在尝试创建一个递归元素,其中包含从我的输入XML中获取的值,似乎我错过了一个循环或导致值以空格出现但不在相应标记下的东西。

这是我得到的输入XML:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
    <ns2:getOrgEntityListByOrgEntityIdsResponse xmlns:ns2="http://client.initiate.com/">
        <OrgEntity>
            <entityId>
                <enterpriseId>269</enterpriseId>
            </entityId>
            <ORG>
                <caudRecno>0</caudRecno>
                <maudRecno>0</maudRecno>
                <memSeqno>0</memSeqno>
                <memVerno>0</memVerno>
                <AccountTypeNameList>
                    <AccountTypeName>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>2</memSeqno>
                        <attrVal>HOSPITAL</attrVal>
                        <elemDecs/>
                    </AccountTypeName>
                </AccountTypeNameList>
                <FacilityTypeNameList>
                    <FacilityTypeName>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>3</memSeqno>
                        <attrVal>HOSPITAL</attrVal>
                        <elemDecs/>
                    </FacilityTypeName>
                </FacilityTypeNameList>
                <FaxNumberList>
                    <FaxNumber>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>12</memSeqno>
                        <custAddressGlobalUniqueIdentifier/>
                        <phoneAreaCode/>
                        <phoneNumber>7704544279</phoneNumber>
                        <sequenceNumber/>
                        <telephoneTypeName/>
                    </FaxNumber>
                </FaxNumberList>
                <InstitutionAddressList>
                    <InstitutionAddress>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>1</memSeqno>
                        <addressSequenceNumber/>
                        <addressTypeDescription/>
                        <custAddressGlobalUniqueIdentifier>12847292</custAddressGlobalUniqueIdentifier>
                        <permanentAddressIndicator/>
                        <sourceAddressLine1>4575 N SHALLOWFORD RD</sourceAddressLine1>
                        <sourceAddressLine2/>
                        <sourceAddressLine3/>
                        <sourceAddressLine4/>
                        <sourceCity>ATLANTA</sourceCity>
                        <sourceClientId/>
                        <sourceCode/>
                        <sourceCountryCode>USA</sourceCountryCode>
                        <sourceCounty/>
                        <sourceState>GA</sourceState>
                        <sourceZip>30338</sourceZip>
                        <sourceZipExtention/>
                        <standardAddressConcatenated>4575NSHALLOWFORDRD30338</standardAddressConcatenated>
                        <standardAddressLine1>4575 N SHALLOWFORD RD</standardAddressLine1>
                        <standardAddressLine2/>
                        <standardAddressLine2Copy/>
                        <standardAddressLine3/>
                        <standardAddressLine4/>
                        <standardCity>ATLANTA</standardCity>
                        <standardCountryCode>USA</standardCountryCode>
                        <standardCounty/>
                        <standardState>GA</standardState>
                        <standardZip>30338</standardZip>
                        <standardZipExtention/>
                    </InstitutionAddress>
                    <InstitutionAddress>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>1</memSeqno>
                        <addressSequenceNumber/>
                        <addressTypeDescription/>
                        <custAddressGlobalUniqueIdentifier>12847292</custAddressGlobalUniqueIdentifier>
                        <permanentAddressIndicator/>
                        <sourceAddressLine1>4575 N SHALLOWFORD RD</sourceAddressLine1>
                        <sourceAddressLine2/>
                        <sourceAddressLine3/>
                        <sourceAddressLine4/>
                        <sourceCity>ATLANTA</sourceCity>
                        <sourceClientId/>
                        <sourceCode/>
                        <sourceCountryCode>USA</sourceCountryCode>
                        <sourceCounty/>
                        <sourceState>GA</sourceState>
                        <sourceZip>30338</sourceZip>
                        <sourceZipExtention/>
                        <standardAddressConcatenated>4575NSHALLOWFORDRD30338rr</standardAddressConcatenated>
                        <standardAddressLine1>4575 N SHALLOWFORD RD</standardAddressLine1>
                        <standardAddressLine2/>
                        <standardAddressLine2Copy/>
                        <standardAddressLine3/>
                        <standardAddressLine4/>
                        <standardCity>ATLANTA</standardCity>
                        <standardCountryCode>USA</standardCountryCode>
                        <standardCounty/>
                        <standardState>GA</standardState>
                        <standardZip>30338</standardZip>
                        <standardZipExtention/>
                    </InstitutionAddress>
                </InstitutionAddressList>
                <InstitutionNameList>
                    <InstitutionName>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>9</memSeqno>
                        <institutionName>EMORY DUNWOODY MEDICAL</institutionName>
                    </InstitutionName>
                </InstitutionNameList>
                <LastChangeTimestampList>
                    <LastChangeTimestamp>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>7</memSeqno>
                        <dateVal>2009-06-19</dateVal>
                    </LastChangeTimestamp>
                </LastChangeTimestampList>
                <NationalProviderIdentifierNumberOrgList>
                    <NationalProviderIdentifierNumberOrg>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>10</memSeqno>
                        <idIssuer>NPI</idIssuer>
                        <idNumber>1679632137</idNumber>
                        <idSrcRecno>0</idSrcRecno>
                    </NationalProviderIdentifierNumberOrg>
                </NationalProviderIdentifierNumberOrgList>
                <OrgAddrKeyList>
                    <OrgAddrKey>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>1</memSeqno>
                        <custAddressGlobalUniqueIdentifier>12847292</custAddressGlobalUniqueIdentifier>
                        <standardAddressConcatenated>4575NSHALLOWFORDRD30338</standardAddressConcatenated>
                    </OrgAddrKey>
                    <OrgAddrKey>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>1</memSeqno>
                        <custAddressGlobalUniqueIdentifier>1284729299</custAddressGlobalUniqueIdentifier>
                        <standardAddressConcatenated>4575NSHALLOWFORDRD30338rr</standardAddressConcatenated>
                    </OrgAddrKey>
                </OrgAddrKeyList>
                <OrgLineageList>
                    <OrgLineage>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>1</memSeqno>
                        <sourceClientId>314612</sourceClientId>
                        <sourceCode>CIMS_HM</sourceCode>
                        <standardAddressConcatenated>4575NSHALLOWFORDRD30338</standardAddressConcatenated>
                    </OrgLineage>
                </OrgLineageList>
                <OrganizationDEANumberList>
                    <OrganizationDEANumber>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>9</memSeqno>
                        <idIssuer>DEA</idIssuer>
                        <idNumber>BE6185323</idNumber>
                        <idSrcRecno>0</idSrcRecno>
                    </OrganizationDEANumber>
                </OrganizationDEANumberList>
                <OrganizationHierarchyList>
                    <OrganizationHierarchy>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>1</memSeqno>
                        <careGroup>Care Group</careGroup>
                        <legalGroup>Legal Group</legalGroup>
                    </OrganizationHierarchy>
                </OrganizationHierarchyList>
                <OrganizationProspectFlagList>
                    <OrganizationProspectFlag>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>4</memSeqno>
                        <attrVal>N</attrVal>
                        <elemDecs/>
                    </OrganizationProspectFlag>
                </OrganizationProspectFlagList>
                <OrganizationSyntheticRecordFlagList>
                    <OrganizationSyntheticRecordFlag>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>5</memSeqno>
                        <attrVal>N</attrVal>
                        <elemDecs/>
                    </OrganizationSyntheticRecordFlag>
                </OrganizationSyntheticRecordFlagList>
                <OrganizationTargetDataList>
                    <OrganizationTargetData>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>1</memSeqno>
                        <targetDocileValue>Target Docile Value</targetDocileValue>
                        <targetLastChangeDate>2012-12-12T12:12:12-08:00</targetLastChangeDate>
                        <targetType>Target Type</targetType>
                    </OrganizationTargetData>
                </OrganizationTargetDataList>
                <SalesOrganizationDescriptionList>
                    <SalesOrganizationDescription>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>6</memSeqno>
                        <attrVal>IV</attrVal>
                        <elemDecs/>
                    </SalesOrganizationDescription>
                </SalesOrganizationDescriptionList>
                <TaxIdentificationNumberList>
                    <TaxIdentificationNumber>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>11</memSeqno>
                        <idIssuer>SSA</idIssuer>
                        <idNumber>581529062</idNumber>
                        <idSrcRecno>0</idSrcRecno>
                    </TaxIdentificationNumber>
                </TaxIdentificationNumberList>
                <TelephoneNumberList>
                    <TelephoneNumber>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>8</memSeqno>
                        <custAddressGlobalUniqueIdentifier>12847292</custAddressGlobalUniqueIdentifier>
                        <phoneAreaCode/>
                        <phoneNumber>770-454-2000</phoneNumber>
                        <sequenceNumber/>
                        <telephoneTypeName/>
                    </TelephoneNumber>
                </TelephoneNumberList>
                <TotalBedCountList>
                    <TotalBedCount>
                        <caudRecno>2</caudRecno>
                        <maudRecno>2</maudRecno>
                        <asaIdxno>0</asaIdxno>
                        <memSeqno>7</memSeqno>
                        <attrVal>118</attrVal>
                        <elemDecs/>
                    </TotalBedCount>
                </TotalBedCountList>
            </ORG>
            <ORGIdList>
                <ORGId>
                    <memIdnum>314612</memIdnum>
                    <srcCode>CIMS_HM</srcCode>
                </ORGId>
                <ORGId>
                    <memIdnum>PO7TWHX5</memIdnum>
                    <srcCode>HMS_IN</srcCode>
                </ORGId>
            </ORGIdList>
        </OrgEntity>
    </ns2:getOrgEntityListByOrgEntityIdsResponse>
</soap:Body>

这是我想写的XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="exslt saxon bpws cis p0 p1 ihmap" version="2.0"
xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
xmlns:cis="http://www.approuter.com/schemas/2003/1/UserCallouts/"
xmlns:exslt="http://exslt.org/common" xmlns:ihmap="http://www.approuter.com/xmlns/2002/Mapping"
xmlns:p0="http://client.initiate.com/"
xmlns:p1="http://www.approuter.com/connectors/request/28/" xmlns:saxon="http://saxon.sf.net/"
xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<xsl:template match="/">
    <xsl:element name="INSTITUTIONS">
        <xsl:for-each select="//OrgEntity">
            <xsl:element name="INSTITUTION">
                <xsl:element name="MDM_EID">
                    <xsl:value-of select="entityId/enterpriseId"/>
                </xsl:element>
                <xsl:element name="ADDRESSES">
                    <xsl:for-each select="ORG/InstitutionAddressList/InstitutionAddress">
                        <xsl:element name="ADDRESS">
                            <xsl:element name="ADDR_TYPE_NM">
                                <xsl:value-of select="standardCity"/>
                            </xsl:element>
                            <xsl:element name="ADDR_SEQ_NR">
                                <xsl:value-of select="standardCountryCode"/>
                            </xsl:element>
                            <xsl:element name="SRC_ADDRESS_LIST">
                                <xsl:element name="SRC_ADDRESS">
                                    <xsl:choose>
                                        <xsl:when
                                            test="//ORG/OrgAddrKeyList/OrgAddrKey[standardAddressConcatenated = //ORG/InstitutionAddressList/InstitutionAddress/standardAddressConcatenated]">
                                            <xsl:element name="SRC_ADDRESS_KEY">
                                              <xsl:value-of
                                              select="//ORG/OrgAddrKeyList/OrgAddrKey/custAddressGlobalUniqueIdentifier"
                                              />
                                            </xsl:element>
                                        </xsl:when>
                                    </xsl:choose>
                                </xsl:element>
                            </xsl:element>
                        </xsl:element>
                    </xsl:for-each>
                </xsl:element>
            </xsl:element>
        </xsl:for-each>
    </xsl:element>
</xsl:template>

预期输出应如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<INSTITUTIONS>
<INSTITUTION>
    <MDM_EID>269</MDM_EID>
    <ADDRESSES>
        <ADDRESS>
            <ADDR_TYPE_NM>ATLANTA</ADDR_TYPE_NM>
            <ADDR_SEQ_NR>USA</ADDR_SEQ_NR>
            <SRC_ADDRESS_LIST>
                <SRC_ADDRESS>
                    <SRC_ADDRESS_KEY>12847292</SRC_ADDRESS_KEY>
                </SRC_ADDRESS>
                <SRC_ADDRESS>
                    <SRC_ADDRESS_KEY>1284729299</SRC_ADDRESS_KEY>
                </SRC_ADDRESS>
            </SRC_ADDRESS_LIST>
        </ADDRESS>
        <ADDRESS>
            <ADDR_TYPE_NM>ATLANTA</ADDR_TYPE_NM>
            <ADDR_SEQ_NR>USA</ADDR_SEQ_NR>
            <SRC_ADDRESS_LIST>
                <SRC_ADDRESS>
                    <SRC_ADDRESS_KEY>12847292</SRC_ADDRESS_KEY>
                </SRC_ADDRESS>
                <SRC_ADDRESS>
                    <SRC_ADDRESS_KEY>1284729299</SRC_ADDRESS_KEY>
                </SRC_ADDRESS>
            </SRC_ADDRESS_LIST>
        </ADDRESS>
    </ADDRESSES>
</INSTITUTION>

然而,我得到的输出看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<INSTITUTIONS>
<INSTITUTION>
    <MDM_EID>269</MDM_EID>
    <ADDRESSES>
        <ADDRESS>
            <ADDR_TYPE_NM>ATLANTA</ADDR_TYPE_NM>
            <ADDR_SEQ_NR>USA</ADDR_SEQ_NR>
            <SRC_ADDRESS_LIST>
                <SRC_ADDRESS>
                    <SRC_ADDRESS_KEY>12847292 1284729299</SRC_ADDRESS_KEY>
                </SRC_ADDRESS>
            </SRC_ADDRESS_LIST>
        </ADDRESS>
        <ADDRESS>
            <ADDR_TYPE_NM>ATLANTA</ADDR_TYPE_NM>
            <ADDR_SEQ_NR>USA</ADDR_SEQ_NR>
            <SRC_ADDRESS_LIST>
                <SRC_ADDRESS>
                    <SRC_ADDRESS_KEY>12847292 1284729299</SRC_ADDRESS_KEY>
                </SRC_ADDRESS>
            </SRC_ADDRESS_LIST>
        </ADDRESS>
    </ADDRESSES>
</INSTITUTION>

对此的任何帮助都将受到高度赞赏。

谢谢!

1 个答案:

答案 0 :(得分:1)

您似乎正在从其连接的地址中查找机构的唯一地址ID。由于一个机构实际上只有一个地址,你应该得到一个而不是两个。 @Tim已在评论中注明。因此,您的SRC_ADDRESS_LIST应该更像这样创建: -

<xsl:element name="SRC_ADDRESS_LIST">
  <xsl:variable name="v" select="standardAddressConcatenated"/>
  <xsl:for-each select='//ORG/OrgAddrKeyList/OrgAddrKey[standardAddressConcatenated=$v]'>
    <xsl:element name="SRC_ADDRESS">
      <xsl:element name="SRC_ADDRESS_KEY">
        <xsl:value-of select="custAddressGlobalUniqueIdentifier"/>
      </xsl:element>
    </xsl:element>
  </xsl:for-each>
</xsl:element>