NAEDI2
asked on
Xpath Expression Help
In the attached stylesheet I need to transform the XML to add various counters the trailer elements. An example is the CTT_347 element that needs to contain the count of the IT1_01 nodes within the same SG0. My code worked well until I had two SG0 nodes in the file. The second CTT_347 node gets the total of all the IT1_01 nodes from all the previous SG0 nodes as well as the current one which is wrong.
Is it possible with a single Xpath expression to get a count of only the IT1_01 nodes within the current SG0 node?
<xsl:template name="HL_segments">
<xsl:choose>
<xsl:when test="name() = 'CTT' ">
<xsl:element name="CTT">
<xsl:element name="idCTT">CTT</xsl:elem ent>
<xsl:element name="CTT_354">
<xsl:value-of select="count(preceding::I T1_01)"/>
</xsl:element>
</xsl:element>
</xsl:when>
<?xml version="1.0" encoding="ISO-8859-1"?>
<ACTIS>
<ISA>
</ISA>
<GS>
</GS>
<SG0>
<ST>
<idST/>
<ST_143>810</ST_143>
<ST_329>0001</ST_329>
</ST>
<BIG>
</BIG>
<IT1_01>
</IT1_01>
<IT1_01>
</IT1_01>
<IT1_01>
</IT1_01>
<IT1_01>
</IT1_01>
<CTT>
<idCTT/>
<CTT_354/>
<CTT_347/>
<CTT_81/>
<CTT_355_01/>
<CTT_183/>
<CTT_355_02/>
<CTT_352/>
</CTT>
<SE>
</SE>
</SG0>
<SG0>
<ST>
<idST/>
<ST_143>810</ST_143>
<ST_329>0002</ST_329>
</ST>
<BIG>
</BIG>
<IT1_01>
</IT1_01>
<IT1_01>
</IT1_01>
<IT1_01>
</IT1_01>
<CTT>
<idCTT/>
<CTT_354/>
<CTT_347/>
<CTT_81/>
<CTT_355_01/>
<CTT_183/>
<CTT_355_02/>
<CTT_352/>
</CTT>
<SE>
</SE>
</SG0>
<GE>
</GE>
<IEA>
</IEA>
</ACTIS>
desadv_x12_856_4010.desadv_x12_856_4.xsl
Edit2.xml
Is it possible with a single Xpath expression to get a count of only the IT1_01 nodes within the current SG0 node?
<xsl:template name="HL_segments">
<xsl:choose>
<xsl:when test="name() = 'CTT' ">
<xsl:element name="CTT">
<xsl:element name="idCTT">CTT</xsl:elem
<xsl:element name="CTT_354">
<xsl:value-of select="count(preceding::I
</xsl:element>
</xsl:element>
</xsl:when>
<?xml version="1.0" encoding="ISO-8859-1"?>
<ACTIS>
<ISA>
</ISA>
<GS>
</GS>
<SG0>
<ST>
<idST/>
<ST_143>810</ST_143>
<ST_329>0001</ST_329>
</ST>
<BIG>
</BIG>
<IT1_01>
</IT1_01>
<IT1_01>
</IT1_01>
<IT1_01>
</IT1_01>
<IT1_01>
</IT1_01>
<CTT>
<idCTT/>
<CTT_354/>
<CTT_347/>
<CTT_81/>
<CTT_355_01/>
<CTT_183/>
<CTT_355_02/>
<CTT_352/>
</CTT>
<SE>
</SE>
</SG0>
<SG0>
<ST>
<idST/>
<ST_143>810</ST_143>
<ST_329>0002</ST_329>
</ST>
<BIG>
</BIG>
<IT1_01>
</IT1_01>
<IT1_01>
</IT1_01>
<IT1_01>
</IT1_01>
<CTT>
<idCTT/>
<CTT_354/>
<CTT_347/>
<CTT_81/>
<CTT_355_01/>
<CTT_183/>
<CTT_355_02/>
<CTT_352/>
</CTT>
<SE>
</SE>
</SG0>
<GE>
</GE>
<IEA>
</IEA>
</ACTIS>
desadv_x12_856_4010.desadv_x12_856_4.xsl
Edit2.xml
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are welcome!
ASKER