我正在尝试将我的xml转换为另一个xml,以便迭代节点的所有子节点都以不同的名称存储在各自的父节点中
XML代码
<changeSummary id="c0C9B039362994319955773B6B7BAB375">
<group groupID="Building" caption="Building" path="/session/data/account/building" id="g770EEC10BBA64DA6B6DC22AAAAA0F092">
<instance dataID="b4BDA8E87A6614C7FAE531A4E84D55EF5" location="1" description="" type="add" id="iDD165B3C64CE4E6EB07871E0AE16415C" />
<instance dataID="b76AACBF9B7954D6FB6FC15E152E0B8AB" location="1" description="" type="add" id="i43428D1464DB4145816579CFC631C392" />
<instance dataID="bE42CE90DDDD541D2B07D5A46A73AD733" location="1" description="" type="add" id="iA5DF81FDAD5F4C1F89EE7D0BD67EE931" />
</group>
<group groupID="BuildingSelect" caption="BuildingSelect" path="/session/data/system/BuildingSelect" id="g4808DF5C47E94C78BB5E3B3939F7B92F">
<instance dataID="BDB2C4E57D71447A79E75875373C0B174" location="1" description="" type="modify" id="i1994EBCB062744FAAD02B7F6D96B4A32">
<change fieldID="BuildingSelectInput.BuildingID" path="BuildingID" fullPath="BuildingID" caption="Building" old="0" new="b4BDA8E87A6614C7FAE531A4E84D55EF5" id="c83BCA4F6848848E29BFDB4E24497C5C0" />
</instance>
</group>
<group groupID="Policy" caption="Policy" path="/session/data/policy" id="g236A029860BC4F66AD540FE9754B4640">
<instance dataID="p9807CAE99CA241D1AF1EA7054FBBBC88" location="1" description="" type="modify" id="iF63B973BF88A4006A57E71B6B6FF1375">
<change fieldID="PolicyOutput.Premium" path="Premium" fullPath="Premium" caption="Full-Term Premium" old="50" new="1006" id="c8C2402698C944589B440C26AE16D1FE8" />
</instance>
</group>
<group groupID="Line" caption="Line" path="/session/data/policy/line[Type="InlandMarineAAIS"]" id="gA15A1CF68FE543D2A969ED86848613AD">
<instance dataID="lA50B4091426F4174AB3449DECEA1A781" location="1" description="" type="modify" id="iBA1D12BC76EB424EABAFABC60DCF2276">
<change fieldID="LineOutput.Premium" path="Premium" fullPath="Premium" caption="Premium" old="50" new="1006" id="c28C0B8E46403463C9E876718773CEED1" />
</instance>
</group>
<group groupID="Transit" caption="Transit" path="/session/data/policy/line[Type="InlandMarineAAIS"]/inlandmarinecoverageforms/coverage[Type="LineTransit"]" id="g3E2195AA85B54CE98657D62ACCA8E6D9">
<instance dataID="cBF3394C001A64CD09615BEBF617B746E" location="1" description="" type="modify" id="iD9CF30C38AB54DB483554F2CCB048431">
<change fieldID="TransitInput.ReportingValueEstimated" path="ReportingValueEstimated" fullPath="ReportingValueEstimated" caption="" old="0" new="13213" id="cE98BF36CBA664B5B8D53E01B25AD00CB" />
<change fieldID="TransitInput.ReportingDepositPremium" path="ReportingDepositPremium" fullPath="ReportingDepositPremium" caption="Reporting Deposit Premium" old="0" new="234" id="cFE0A32DA97194A5491F86D21E2E1C0DA" />
</instance>
<instance dataID="c59C840E208C84EE3AAA22EAFFF350B19" location="1" description="" type="modify" id="iD4E74CE616BF4BFE8FF8FACCAC44C91B">
<change fieldID="TransitUnderwriting.CatastropheLimit" path="limit[Type="Catastrophe"]/iValue" fullPath="limit[Type="Catastrophe"]/iValue" caption="Catastrophe Limit" old="0" new="02424" id="c409AA6D0CF924160B97EAD7EB719E9BD" />
<change fieldID="TransitInput.TripTransitModification" path="TripTransitModification" fullPath="TripTransitModification" caption="Trip Transit Modification" old="1" new="12424" id="cD4A6EB245CE34EDA9A17C9981163A4D6" />
</instance>
</group>
<group groupID="Risk" caption="Risk" path="/session/data/policy/line[Type="InlandMarineAAIS"]/risk" id="g68E2B05DA0AA44D38E7BF8512FE82701">
<instance dataID="r998DC26F558A46A0829200B3A55A7FA6" location="1" description="" type="add" id="i85089A5E8D7E46F097BC7F65DBC71761" />
<instance dataID="r51353AF95FDD4666A8039ED7A3604608" location="1" description="" type="add" id="i1935D0FEC66E4FD48E374F638BC3DA34" />
</group>
<group groupID="CoverageElectronicDataProcessing" caption="CoverageElectronicDataProcessing" path="/session/data/policy/line[Type="InlandMarineAAIS"]/risk/coverage[Type="ElectronicDataProcessing"]" id="gEF9BBABE5E2D4634AAB844FFBC265267">
<instance dataID="c4B9061DFF1BC47FCA863532952EC1037" location="1" description="" type="add" id="i2A9997BC4D2641FC889253E900CEDAF8" />
<instance dataID="c8D5E555101684F56A326C335FC7614DD" location="1" description="" type="add" id="iAE7314C8CA754A82977428A9F6DDB009" />
</group>
<group groupID="Agency" caption="Agency" path="/session/data/agencyDetails" id="g0E6DF1F792F64A03811DA2F8026D443C">
<instance dataID="aD9E2C7F10CCB4FCCAB7A5EEBC56B8961" location="1" description="" type="delete" id="i048431E9A7F745418779A8FEC53AECEE" />
<instance dataID="a2577D263222548AE99D6E20C1945A33C" location="1" description="" type="add" id="iC22B7F58DED546F4AC2FC93435AF91D8" />
</group>
<group groupID="StatCodeRiskCoverageGroup" caption="StatCodeRiskCoverageGroup" path="/session/data///line[Type="InlandMarineAAIS"]/risk/coverage[Indicator=1]" id="gA7F2C7C30EE04777AA56FF009112385E">
<instance dataID="c4B9061DFF1BC47FCA863532952EC1037" location="1" description="" type="add" id="i5253953C118C4959B0D71B83E3F53D5E" />
<instance dataID="c8D5E555101684F56A326C335FC7614DD" location="1" description="" type="add" id="iBA5AC5441B604E949F18E97C30B92E6E" />
</group>
<group groupID="StatCodeLineCoverageGroup" caption="StatCodeLineCoverageGroup" path="/session/data///line[Type="InlandMarineAAIS"]/coverage[Indicator=1]" id="gB14B74154A5B4B11AD2CA385E291FF24">
<instance dataID="c21147C01698C4F228CD35AD209CC336D" location="1" description="" type="delete" id="i5FBF405EEEEA41D1A4C59BD2E0A88E96" />
<instance dataID="cE172687562EB4219BFA50D9B3BA276B8" location="1" description="" type="modify" id="i2C1CD873479B4493A447396C12B573D5">
<change fieldID="StatCodeLineCoverageGroupInput.StatCodePremium" path="Premium" fullPath="Premium" caption="Premium" old="0" new="10" id="cD967D42BA3A94C23906B1B62D951E4DE" />
</instance>
</group>
<group groupID="StatCodeLineCoverageFormsGroup" caption="StatCodeLineCoverageFormsGroup" path="/session/data///line[Type="InlandMarineAAIS"]/inlandmarinecoverageforms/coverage" id="g5FBD83AB961342FC9D1BAE55BB08DF90">
<instance dataID="cBF3394C001A64CD09615BEBF617B746E" location="1" description="" type="modify" id="i593B67183F054A2E85754BE6E2318F28">
<change fieldID="StatCodeLineCoverageFormsGroupInput.StatCodePremium" path="Premium" fullPath="Premium" caption="Premium" old="0" new="996" id="c541E903134B94A6298F24044E0C76BD0" />
</instance>
</group>
我当前的xslt:
<xsl:template match="changeSummary">
<xsl:element name="CovTransitResponse">
<xsl:for-each select="//changeSummary/group[@groupID = 'Transit']/instance">
<xsl:copy>
<xsl:element name="CovGroupType">
<xsl:value-of select="@id" />
</xsl:element>
<xsl:element name="CovID">
<xsl:value-of select="@dataID" />
</xsl:element>
<xsl:element name="CovType">
<xsl:value-of select="@type" />
</xsl:element>
<xsl:for-each select="//changeSummary/group[@groupID = 'Transit']/instance/change">
<xsl:copy>
<xsl:element name="ChangeFieldID">
<xsl:value-of select="@fieldID" />
</xsl:element>
<xsl:element name="ChangeNewValue">
<xsl:value-of select="@new" />
</xsl:element>
<xsl:element name="ChangeOldValue">
<xsl:value-of select="@old" />
</xsl:element>
<xsl:element name="ChangeCaption">
<xsl:value-of select="@caption" />
</xsl:element>
<xsl:element name="ChangePath">
<xsl:value-of select="@path" />
</xsl:element>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:for-each>
</xsl:element>
</xsl:template>
预期产出:
<CovTransitResponse>
<instance>
<CovGroupType>iD9CF30C38AB54DB483554F2CCB048431</CovGroupType>
<CovID>cBF3394C001A64CD09615BEBF617B746E</CovID>
<CovType>modify</CovType>
<change>
<ChangeFieldID>TransitInput.ReportingValueEstimated</ChangeFieldID>
<ChangeNewValue>13213</ChangeNewValue>
<ChangeOldValue>0</ChangeOldValue>
<ChangeCaption></ChangeCaption>
<ChangePath>ReportingValueEstimated</ChangePath>
</change>
<change>
<ChangeFieldID>TransitInput.ReportingDepositPremium</ChangeFieldID>
<ChangeNewValue>234</ChangeNewValue>
<ChangeOldValue>0</ChangeOldValue>
<ChangeCaption>Reporting Deposit Premium</ChangeCaption>
<ChangePath>ReportingDepositPremium</ChangePath>
</change>
</instance>
<instance>
<CovGroupType>iD4E74CE616BF4BFE8FF8FACCAC44C91B</CovGroupType>
<CovID>c59C840E208C84EE3AAA22EAFFF350B19</CovID>
<CovType>modify</CovType>
<change>
<ChangeFieldID>TransitUnderwriting.CatastropheLimit</ChangeFieldID>
<ChangeNewValue>02424</ChangeNewValue>
<ChangeOldValue>0</ChangeOldValue>
<ChangeCaption>Catastrophe Limit</ChangeCaption>
<ChangePath>limit[Type="Catastrophe"]/iValue</ChangePath>
</change>
<change>
<ChangeFieldID>TransitInput.TripTransitModification</ChangeFieldID>
<ChangeNewValue>12424</ChangeNewValue>
<ChangeOldValue>1</ChangeOldValue>
<ChangeCaption>Trip Transit Modification</ChangeCaption>
<ChangePath>TripTransitModification</ChangePath>
</change>
</instance>
</CovTransitResponse>
当前输出:
<CovTransitResponse>
<instance>
<CovGroupType>iD9CF30C38AB54DB483554F2CCB048431</CovGroupType>
<CovID>cBF3394C001A64CD09615BEBF617B746E</CovID>
<CovType>modify</CovType>
<change>
<ChangeFieldID>TransitInput.ReportingValueEstimated</ChangeFieldID>
<ChangeNewValue>13213</ChangeNewValue>
<ChangeOldValue>0</ChangeOldValue>
<ChangeCaption></ChangeCaption>
<ChangePath>ReportingValueEstimated</ChangePath>
</change>
<change>
<ChangeFieldID>TransitInput.ReportingDepositPremium</ChangeFieldID>
<ChangeNewValue>234</ChangeNewValue>
<ChangeOldValue>0</ChangeOldValue>
<ChangeCaption>Reporting Deposit Premium</ChangeCaption>
<ChangePath>ReportingDepositPremium</ChangePath>
</change>
<change>
<ChangeFieldID>TransitUnderwriting.CatastropheLimit</ChangeFieldID>
<ChangeNewValue>02424</ChangeNewValue>
<ChangeOldValue>0</ChangeOldValue>
<ChangeCaption>Catastrophe Limit</ChangeCaption>
<ChangePath>limit[Type="Catastrophe"]/iValue</ChangePath>
</change>
<change>
<ChangeFieldID>TransitInput.TripTransitModification</ChangeFieldID>
<ChangeNewValue>12424</ChangeNewValue>
<ChangeOldValue>1</ChangeOldValue>
<ChangeCaption>Trip Transit Modification</ChangeCaption>
<ChangePath>TripTransitModification</ChangePath>
</change>
</instance>
<instance>
<CovGroupType>iD4E74CE616BF4BFE8FF8FACCAC44C91B</CovGroupType>
<CovID>c59C840E208C84EE3AAA22EAFFF350B19</CovID>
<CovType>modify</CovType>
<change>
<ChangeFieldID>TransitInput.ReportingValueEstimated</ChangeFieldID>
<ChangeNewValue>13213</ChangeNewValue>
<ChangeOldValue>0</ChangeOldValue>
<ChangeCaption></ChangeCaption>
<ChangePath>ReportingValueEstimated</ChangePath>
</change>
<change>
<ChangeFieldID>TransitInput.ReportingDepositPremium</ChangeFieldID>
<ChangeNewValue>234</ChangeNewValue>
<ChangeOldValue>0</ChangeOldValue>
<ChangeCaption>Reporting Deposit Premium</ChangeCaption>
<ChangePath>ReportingDepositPremium</ChangePath>
</change>
<change>
<ChangeFieldID>TransitUnderwriting.CatastropheLimit</ChangeFieldID>
<ChangeNewValue>02424</ChangeNewValue>
<ChangeOldValue>0</ChangeOldValue>
<ChangeCaption>Catastrophe Limit</ChangeCaption>
<ChangePath>limit[Type="Catastrophe"]/iValue</ChangePath>
</change>
<change>
<ChangeFieldID>TransitInput.TripTransitModification</ChangeFieldID>
<ChangeNewValue>12424</ChangeNewValue>
<ChangeOldValue>1</ChangeOldValue>
<ChangeCaption>Trip Transit Modification</ChangeCaption>
<ChangePath>TripTransitModification</ChangePath>
</change>
</instance>
</CovTransitResponse>
我知道预期的输出是错误的,因为我从xml的根目录中选择了第二个select子句。在第一次选择父节点之后,是否有任何方法可以在每次选择中使用第二个节点,以便所有子节点都在其各自的父节点内。