i'm new xslt , i'm struggling transformation nested structure flat sequence of elements. input following:
<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>
the output should list of elements following
<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>
my xslt not working @ since iterating in 1 element @ each time , cannot find way iterate on elements , right values in same structure.
<xsl:template match="/"> <xsl:for-each select="/syncbillofmaterialslistebm/dataarea/syncbillofmaterialslist"> <xsl:choose> <xsl:when test="/syncbillofmaterialslistebm/dataarea/syncbillofmaterialslist[position()]/billofmaterialscomponentitem/identification/businesscomponentid/@schemeid != '' , /syncbillofmaterialslistebm/dataarea/syncbillofmaterialslist[position()]/billofmaterialscomponentitem/identification/id!='' , /syncbillofmaterialslistebm/dataarea/syncbillofmaterialslist[position()]/billofmaterialscomponentitem/billofmaterialssubstitutecomponentitem/itemreference/itemidentification/id!='' , /syncbillofmaterialslistebm/dataarea/syncbillofmaterialslist[position()]/identification/id=/syncbillofmaterialslistebm/dataarea/syncbillofmaterialslist[position()]/billofmaterialscomponentitem/identification/businesscomponentid@schemeid , /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 != '' , /syncbillofmaterialslistebm/dataarea/syncbillofmaterialslist[position()]/billofmaterialscomponentitem/identification/id!='' , /syncbillofmaterialslistebm/dataarea/syncbillofmaterialslist[position()]/billofmaterialscomponentitem/billofmaterialssubstitutecomponentitem/itemreference/itemidentification/id='' , /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>
any appreciated, take me lot of struggle create , manipulate variable point in right value.
this not produce well-formedxml, because template matches root node results in document 3 document elements.
your xslt not well-formed. having closed first when element, need open one.
if find writing
for-each
, trying test characteristic of node in question, should using apply-templates instead.none of
revised_item_name
elements populated, there nosyncbillofmaterialslist
element child element ofsyncbillofmaterialslistebm
.create xpath expressions relative context node, rather trying find again document root based on
position()
. e.g. instead of:/syncbillofmaterialslistebm/dataarea/syncbillofmaterialslist[position()]/billofmaterialscomponentitem/identification/businesscomponentid/@schemeid
, usebillofmaterialscomponentitem/identification/businesscomponentid/@schemeid
. more readable, , use ofposition()
can fragile, not refer ordinal position of node within parent, position within current node list. if have xpath expression explicitly selects node fifth child within parent,position()
1, not 5.don't try create whole tree based on collection of conditions evaluated @ once. looks each
inputparameters
element in output has same shape, different values. insyncbillofmaterialslist
template, specify shape ofinputparameters
tree once, , populate child elements conditionally. far more maintainable , easy read.
Comments
Post a Comment