我是XSLT的新手,我正在努力從嵌套結構轉換爲平面元素序列。 我的輸入是這樣的: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/[email protected] AND /SyncBillOfMaterialsListEBM/DataArea/SyncBillOfMaterialsList[position()]/BillOfMaterialsComponentItem/Identification/[email protected]=/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/[email protected]">
<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>
任何幫助都非常值得讚賞,創建和操縱變量以指向正確的值需要我很多努力。