我是 XSLT 的新手,我正在努力将嵌套结构转换为扁平的元素序列。我的输入如下:
<SyncBillOfMaterialsListEBM>
<EBMHeader/>
<DataArea>
<Sync/>
<SyncBillOfMaterialsList/>
<SyncBillOfMaterialsList>
<Identification>
<ID>B31819K</ID>
<ContextID schemeID="AddedBOMs"/>
</Identification>
<BillOfMaterialsComponentItem/>
</SyncBillOfMaterialsList>
<SyncBillOfMaterialsList>
<Identification/>
<BillOfMaterialsComponentItem>
<Identification>
<BusinessComponentID schemeID="B31819K"/>
<ID>B31618R</ID>
<ContextID schemeID="AddedBOMComponents"/>
</Identification>
<Quantity>5</Quantity>
<FromUnitNumber>500</FromUnitNumber>
<TypeCode>IT1</TypeCode>
<BillOfMaterialsSubstituteComponentItem/>
</BillOfMaterialsComponentItem>
</SyncBillOfMaterialsList>
<SyncBillOfMaterialsList>
<Identification/>
<BillOfMaterialsComponentItem>
<Identification>
<BusinessComponentID schemeID="B31819K"/>
<ID>B31619S</ID>
<ContextID schemeID="AddedBOMComponents"/>
</Identification>
<Quantity>2</Quantity>
<FromUnitNumber>600</FromUnitNumber>
<TypeCode>IT1</TypeCode>
</BillOfMaterialsComponentItem>
</SyncBillOfMaterialsList>
<SyncBillOfMaterialsList>
<Identification/>
<BillOfMaterialsComponentItem>
<Identification/>
<BillOfMaterialsSubstituteComponentItem>
<Identification>
<BusinessComponentID schemeID="B31819K"/>
<ID>B31618R</ID>
<ContextID schemeID="AddedSubstitutes"/>
</Identification>
<Quantity>5</Quantity>
<ItemReference>
<ItemIdentification>
<ID>B31619S</ID>
</ItemIdentification>
<SpecificationGroup/>
</ItemReference>
<ChangeTypeCode>IT1</ChangeTypeCode>
</BillOfMaterialsSubstituteComponentItem>
</BillOfMaterialsComponentItem>
</SyncBillOfMaterialsList>
<SyncBillOfMaterialsList>
<Identification/>
<BillOfMaterialsComponentItem>
<Identification/>
<BillOfMaterialsSubstituteComponentItem>
<Identification>
<BusinessComponentID schemeID="B31819K"/>
<ID>B31619S</ID>
<ContextID schemeID="AddedSubstitutes"/>
</Identification>
<Quantity>2</Quantity>
<ItemReference>
<ItemIdentification>
<ID>B31820L</ID>
</ItemIdentification>
</ItemReference>
<ChangeTypeCode>IT1</ChangeTypeCode>
</BillOfMaterialsSubstituteComponentItem>
</BillOfMaterialsComponentItem>
</SyncBillOfMaterialsList>
输出应该是一个元素列表,如下所示
<InputParameters>
<REV_ITEM>
<REVISED_ITEM_NAME>B31819K</REVISED_ITEM_NAME>
</REV_ITEML>
<REV_COMP>
<COMPONENT_ITEM_NAME>B31618R</COMPONENT_ITEM_NAME>
</REV_COMP>
<SUB_COMP_TBL_ITEM>
<REVISED_ITEM_NAME>B31819K</REVISED_ITEM_NAME>
<COMPONENT_ITEM_NAME>B31618R</COMPONENT_ITEM_NAME>
<SUBSTITUTE_COMPONENT_NAME>B31619S</SUBSTITUTE_COMPONENT_NAME>
<SUBSTITUTE_ITEM_QUANTITY>5</SUBSTITUTE_ITEM_QUANTITY>
</SUB_COMP_TBL_ITEM>
</InputParameters>
<InputParameters>
<REV_ITEM>
<REVISED_ITEM_NAME>B31819K</REVISED_ITEM_NAME>
</REV_ITEML>
<REV_COMP>
<COMPONENT_ITEM_NAME>B31618S</COMPONENT_ITEM_NAME>
</REV_COMP>
<SUB_COMP_TBL_ITEM>
<REVISED_ITEM_NAME>B31819K</REVISED_ITEM_NAME>
<COMPONENT_ITEM_NAME>B31618S</COMPONENT_ITEM_NAME>
<SUBSTITUTE_COMPONENT_NAME>B31619L</SUBSTITUTE_COMPONENT_NAME>
<SUBSTITUTE_ITEM_QUANTITY>2</SUBSTITUTE_ITEM_QUANTITY>
</SUB_COMP_TBL_ITEM>
</InputParameters>
我的 XSLT 根本不工作,因为每次只在一个元素中迭代,我找不到迭代所有元素并在同一结构中获得正确值的方法。
<xsl:template match="/">
<xsl:for-each select="/SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList">
<xsl:choose>
<xsl:when test="/SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/Identification/BusinessComponentID/@schemeID != '' AND /SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/Identification/ID!='' AND /SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/BillOfMaterialsSubstituteComponentItem/ItemReference/ItemIdentification/ID!='' AND /SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/Identification/ID=/SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/Identification/BusinessComponentID@schemeID AND /SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/Identification/BusinessComponentID@schemeID=/SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/BillOfMaterialsSubstituteComponentItem/ItemReference/ItemIdentification/ID >
<REV_ITEM>
<REVISED_ITEM_NAME><xsl:value-of select="SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/Identification/ID"/></REVISED_ITEM_NAME>
</REV_ITEML>
<REV_COMP>
<COMPONENT_ITEM_NAME><xsl:value-of select="/SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/Identification/ID" /></COMPONENT_ITEM_NAME>
</REV_COMP>
<SUB_COMP_TBL_ITEM>
<REVISED_ITEM_NAME><xsl:value-of select="SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/Identification/ID"/></REVISED_ITEM_NAME>
<COMPONENT_ITEM_NAME><xsl:value-of select="/SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/ComponentItemProcessingInstruction/Identification/ID" /></COMPONENT_ITEM_NAME>
<SUBSTITUTE_COMPONENT_NAME><xsl:value-of select="/SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/BillOfMaterialsSubstituteComponentItem/ItemReference/ItemIdentification/ID"/></SUBSTITUTE_COMPONENT_NAME>
<SUBSTITUTE_ITEM_QUANTITY><xsl:value-of select="/SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/BillOfMaterialsSubstituteComponentItem/Quantity"/></SUBSTITUTE_ITEM_QUANTITY>
</SUB_COMP_TBL_ITEM>
</xsl:when test="/SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/Identification/BusinessComponentID/@schemeID != '' AND /SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/Identification/ID!='' AND /SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/BillOfMaterialsSubstituteComponentItem/ItemReference/ItemIdentification/ID='' AND /SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/Identification/ID=/SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/Identification/BusinessComponentID@schemeID">
<REV_ITEM>
<REVISED_ITEM_NAME><xsl:value-of select="SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/Identification/ID"/></REVISED_ITEM_NAME>
</REV_ITEML>
<REV_COMP>
<COMPONENT_ITEM_NAME><xsl:value-of select="/SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/Identification/ID" /></COMPONENT_ITEM_NAME>
</REV_COMP>
<SUB_COMP_TBL_ITEM>
<REVISED_ITEM_NAME><!--empty--></REVISED_ITEM_NAME>
<COMPONENT_ITEM_NAME><!--empty--></COMPONENT_ITEM_NAME>
<SUBSTITUTE_COMPONENT_NAME><!--empty--></SUBSTITUTE_COMPONENT_NAME>
<SUBSTITUTE_ITEM_QUANTITY><!--empty--></SUBSTITUTE_ITEM_QUANTITY>
</SUB_COMP_TBL_ITEM>
</xsl:when>
<xsl:when OTHERPOSIBILITIES>
</xsl:when>
<xsl:otherwise>
<!-- EMPTY -->
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
非常感谢任何帮助,创建和操作变量以指向正确的值需要我付出很多努力。