我想使用XSLT将机器生成的策略元素转换为insurance_policy_group元素中的集合方元素。 policy元素中的每个元素都应该表示为insurance_policy_group中的party元素。策略中的policy_holders数量是无限的,legal_reps和main_claimant也是如此。生成XML的机器使用字母/数字后缀来生成元素(如果有多个元素)。这是第三方API,所以我只知道policy_holder。 legal_rep元素最后会有一个数字或字母后缀。例如,如果有2个策略持有者,则policy元素可能包含policy_holder_1和policy_holder_a。请向下滚动以查看输出
我的目标是将元素转换为元素。对于每个policy_holder或legal_rep,我需要在insurance_party_group中创建一个party元素。请记住,策略XML是机器生成的,因此可能看起来很奇怪。不幸的是,我只在XSLT中完成了基本的转换。
<!-- Machine generated XML from calling a service, this should be used
for the transformation -->
<policy>
<policy_holder>Dan Glover</policy_holder>
<policy_holder_address1>4 Lemming Street</policy_holder_address1>
<policy_holder_address2></policy_holder_address2>
<policy_holder_city>Dickinson</policy_holder_city>
<policy_holder_state>ND</policy_holder_state>
<policy_holder_zip>551221</policy_holder_zip>
<policy_holder_1>Sherie Glover</policy_holder_1>
<policy_holder_address1__1>4 Lemming Street</policy_holder_address1_1>
<policy_holder_address2_1>Dickinson</policy_holder_address2_1>
<policy_holder_city_1></policy_holder_city_1>
<policy_holder_state_1>ND</policy_holder_state_1>
<policy_holder_zip_1>551221<policy_holder_zip_1>
<main_claimaint_b>Sherie Glover</main_claimaint_b>
<main_claimaint_address1__b>4 Lemming Street</main_claimaint_address1_b>
<main_claimaint_address2_b>Dickinson</main_claimaint_address2_b>
<main_claimaint_city_b></main_claimaint_city_b>
<main_claimaint_state_b>ND</main_claimaint_state_b>
<main_claimaintr_zip_b>551221<main_claimaint_zip_b>
<legal_rep_a>Major Parksinson</legal_rep_a>
<legal_rep_address1__a>4511 Durham Road</legal_rep_address1_a>
<legal_rep_address2_a>Dickinson</legal_rep_address2_a>
<legal_rep_city_a></legal_rep_city_a>
<legal_rep_state_a>ND</legal_rep_state_a>
<legal_rep_zip_a>55124<legal_rep_zip_a>
<legal_rep_1>Tom Lynch/legal_rep_1>
<legal_rep_address1__1>44511 Durham Road</legal_rep_address1_1>
<legal_rep_address2_1>Dickinson</legal_rep_address2_1>
<legal_rep_city_1></legal_rep_city_1>
<legal_rep_state_1>ND</legal_rep_state_1>
<legal_rep_zip_1>551221<legal_rep_zip_1>
</policy>
<!-- Expected output, the result of applying a stylesheet on the machine
generated XML above -->
<insurance_party_group>
<party>
<name>Dan Glover</Name>
<addressText1>4 Lemming Street</addressText1>
<addressText2></addressText2>
<city>Dickinson</city>
<state>ND</state>
<zipCode>551221</zipCode>
<participant_type>CLAIMANT</participant_type>
</party>
<party>
<name>Sherie Glover</Name>
<addressText1>4 Lemming Street</addressText1>
<addressText2></addressText2>
<city>Dickinson</city>
<state>ND</state>
<zipCode>551221</zipCode>
<participant_type>PRINCIPAL_CLAIMANT</participant_type>
</party>
<party>
<name>Major Parksinson</Name>
<addressText1>4511 Durham Road</addressText1>
<addressText2></addressText2>
<city>Dickinson</city>
<state>ND</state>
<zipCode>55124</zipCode>
<participant_type>LEGAL</participant_type>
</party>
<party>
<name>Tom Lynch</Name>
<addressText1>4511 Durham Road</addressText1>
<addressText2></addressText2>
<city>Dickinson</city>
<state>ND</state>
<zipCode>55124</zipCode>
<participant_type>LEGAL</participant_type>
</party>
</insurance_party_group>