Global counter XSLT 1.0












0















This is my XML input that I have to transform:



<_-FOX_-SHPMNT06>
<IDOC BEGIN="1">
<E1EDT20 SEGMENT="1">
<TKNUM>8201333969</TKNUM>
<TPBEZ>FDC Domestic YT</TPBEZ`
<E1EDL20 SEGMENT="1">
<VBELN>3460011248</VBELN>
<E1EDT13 SEGMENT="1">
<QUALF>015</QUALF>
<NTANF>20181016</NTANF>
<NTANZ>000000</NTANZ>
<NTEND>20181016</NTEND>
<NTENZ>000000</NTENZ>
<ISDD>00000000</ISDD>
<ISDZ>000000</ISDZ>
<IEDD>00000000</IEDD>
<IEDZ>000000</IEDZ>
</E1EDT13>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z022</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Der Unterzeichner erklärt, dass die in diesem Dokument aufgeführten</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>Waren Ursprungserzeugnisse aus China sind und im Präferenzverkehr mit</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>CH-EU entsprechen.</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
</E1TXTP8>
</E1TXTH8>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z024</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Ihre Artikelnr. 0068018</TDLINE>
</E1TXTP8>
</E1TXTH8>
</E1EDL20>
</E1EDT20>
</IDOC>
</_-FOX_-SHPMNT06>


and this is what I need as XML result:



<_-FOX_-SHPMNT06>
<IDOC BEGIN="1">
<E1EDT20 SEGMENT="1">
<TKNUM>8201333969</TKNUM>
<TPBEZ>FDC Domestic YT</TPBEZ>
<E1EDL20 SEGMENT="1">
<VBELN>3460011248</VBELN>
<E1TXTH8 SEGMENT="1">
<TDOBJECT/>
<TDOBNAME/>
<TDID/>
<TDSPRAS/>
<LANGUA_ISO/>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 01 E Der Unterzeichner erklärt, dass die in diesem Dokument aufgeführten</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 02 E Waren Ursprungserzeugnisse aus China sind und im Präferenzverkehr mit</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 03 E CH-EU entsprechen.</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 04 E </TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 05 E Ihre Artikelnr. 0068018</TDLINE>
</E1TXTP8>
</E1TXTH8>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z022</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Der Unterzeichner erklärt, dass die in diesem Dokument aufgeführten</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>Waren Ursprungserzeugnisse aus China sind und im Präferenzverkehr mit</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>CH-EU entsprechen.</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
</E1TXTP8>
</E1TXTH8>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z024</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Ihre Artikelnr. 0068018</TDLINE>
</E1TXTP8>
</E1TXTH8>
</E1EDL20>
</E1EDT20>
</IDOC>
</_-FOX_-SHPMNT06>


I need to get a global counter instead of using "position()" because I don't want the counter to reset to 0 in every "for-each":



<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<!-- Identity template : copy all text nodes, elements and attributes -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="E1EDT13[position()=last()]">
<E1TXTH8 SEGMENT="1">
<TDOBJECT/>
<TDOBNAME/>
<TDID/>
<TDSPRAS/>
<LANGUA_ISO/>
<xsl:for-each select="following-sibling::E1TXTH8[TDID='Z002']/E1TXTP8">
<E1TXTP8 SEGMENT="1">
<xsl:variable name="typeA">A</xsl:variable>
<TDFORMAT/>
<TDLINE>
<xsl:value-of select="concat('@', ' ', format-number(position(),'00'), ' ', $typeA, ' ', TDLINE)"/>
</TDLINE>
</E1TXTP8>
</xsl:for-each>
<xsl:for-each select="following-sibling::E1TXTH8[TDID='Z022']/E1TXTP8">
<E1TXTP8 SEGMENT="1">
<xsl:variable name="typeE">E</xsl:variable>
<TDFORMAT/>
<TDLINE>
<xsl:value-of select="concat('@', ' ', format-number(position(),'00'), ' ', $typeE, ' ', TDLINE)"/>
</TDLINE>
</E1TXTP8>
</xsl:for-each>
<xsl:for-each select="following-sibling::E1TXTH8[TDID='Z024']/E1TXTP8">
<E1TXTP8 SEGMENT="1">
<xsl:variable name="typeE">E</xsl:variable>
<TDFORMAT/>
<TDLINE>
<xsl:value-of select="concat('@', ' ', format number(position(),'00'), ' ', $typeE, ' ', TDLINE)"/>
</TDLINE>
</E1TXTP8>
</xsl:for-each>
</E1TXTH8>
</xsl:template>
</xsl:stylesheet>


Is there any way to manage it ? If I use "position()" the counters will be 01 02 03 04 01 and I need 01 02 03 04 05 even if I have more "for each"










share|improve this question

























  • Your question is not clear. Please post a Minimal, Complete, and Verifiable example, including the input and the expected output. -- In general, you can use xsl:number to control how the current node is numbered.

    – michael.hor257k
    Nov 19 '18 at 12:31











  • More information added

    – Luca
    Nov 19 '18 at 12:50











  • But the input is not well-formed XML. And it has no E1EDT13 element, so your template does not match anything. Please refer again to: Minimal, Complete, and Verifiable example.

    – michael.hor257k
    Nov 19 '18 at 12:52













  • E1EDT13 element added

    – Luca
    Nov 19 '18 at 12:58











  • And the input is still not well-formed XML (no root element). And now I have exhausted the time I am willing to spend on this.

    – michael.hor257k
    Nov 19 '18 at 13:08
















0















This is my XML input that I have to transform:



<_-FOX_-SHPMNT06>
<IDOC BEGIN="1">
<E1EDT20 SEGMENT="1">
<TKNUM>8201333969</TKNUM>
<TPBEZ>FDC Domestic YT</TPBEZ`
<E1EDL20 SEGMENT="1">
<VBELN>3460011248</VBELN>
<E1EDT13 SEGMENT="1">
<QUALF>015</QUALF>
<NTANF>20181016</NTANF>
<NTANZ>000000</NTANZ>
<NTEND>20181016</NTEND>
<NTENZ>000000</NTENZ>
<ISDD>00000000</ISDD>
<ISDZ>000000</ISDZ>
<IEDD>00000000</IEDD>
<IEDZ>000000</IEDZ>
</E1EDT13>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z022</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Der Unterzeichner erklärt, dass die in diesem Dokument aufgeführten</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>Waren Ursprungserzeugnisse aus China sind und im Präferenzverkehr mit</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>CH-EU entsprechen.</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
</E1TXTP8>
</E1TXTH8>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z024</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Ihre Artikelnr. 0068018</TDLINE>
</E1TXTP8>
</E1TXTH8>
</E1EDL20>
</E1EDT20>
</IDOC>
</_-FOX_-SHPMNT06>


and this is what I need as XML result:



<_-FOX_-SHPMNT06>
<IDOC BEGIN="1">
<E1EDT20 SEGMENT="1">
<TKNUM>8201333969</TKNUM>
<TPBEZ>FDC Domestic YT</TPBEZ>
<E1EDL20 SEGMENT="1">
<VBELN>3460011248</VBELN>
<E1TXTH8 SEGMENT="1">
<TDOBJECT/>
<TDOBNAME/>
<TDID/>
<TDSPRAS/>
<LANGUA_ISO/>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 01 E Der Unterzeichner erklärt, dass die in diesem Dokument aufgeführten</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 02 E Waren Ursprungserzeugnisse aus China sind und im Präferenzverkehr mit</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 03 E CH-EU entsprechen.</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 04 E </TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 05 E Ihre Artikelnr. 0068018</TDLINE>
</E1TXTP8>
</E1TXTH8>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z022</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Der Unterzeichner erklärt, dass die in diesem Dokument aufgeführten</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>Waren Ursprungserzeugnisse aus China sind und im Präferenzverkehr mit</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>CH-EU entsprechen.</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
</E1TXTP8>
</E1TXTH8>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z024</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Ihre Artikelnr. 0068018</TDLINE>
</E1TXTP8>
</E1TXTH8>
</E1EDL20>
</E1EDT20>
</IDOC>
</_-FOX_-SHPMNT06>


I need to get a global counter instead of using "position()" because I don't want the counter to reset to 0 in every "for-each":



<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<!-- Identity template : copy all text nodes, elements and attributes -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="E1EDT13[position()=last()]">
<E1TXTH8 SEGMENT="1">
<TDOBJECT/>
<TDOBNAME/>
<TDID/>
<TDSPRAS/>
<LANGUA_ISO/>
<xsl:for-each select="following-sibling::E1TXTH8[TDID='Z002']/E1TXTP8">
<E1TXTP8 SEGMENT="1">
<xsl:variable name="typeA">A</xsl:variable>
<TDFORMAT/>
<TDLINE>
<xsl:value-of select="concat('@', ' ', format-number(position(),'00'), ' ', $typeA, ' ', TDLINE)"/>
</TDLINE>
</E1TXTP8>
</xsl:for-each>
<xsl:for-each select="following-sibling::E1TXTH8[TDID='Z022']/E1TXTP8">
<E1TXTP8 SEGMENT="1">
<xsl:variable name="typeE">E</xsl:variable>
<TDFORMAT/>
<TDLINE>
<xsl:value-of select="concat('@', ' ', format-number(position(),'00'), ' ', $typeE, ' ', TDLINE)"/>
</TDLINE>
</E1TXTP8>
</xsl:for-each>
<xsl:for-each select="following-sibling::E1TXTH8[TDID='Z024']/E1TXTP8">
<E1TXTP8 SEGMENT="1">
<xsl:variable name="typeE">E</xsl:variable>
<TDFORMAT/>
<TDLINE>
<xsl:value-of select="concat('@', ' ', format number(position(),'00'), ' ', $typeE, ' ', TDLINE)"/>
</TDLINE>
</E1TXTP8>
</xsl:for-each>
</E1TXTH8>
</xsl:template>
</xsl:stylesheet>


Is there any way to manage it ? If I use "position()" the counters will be 01 02 03 04 01 and I need 01 02 03 04 05 even if I have more "for each"










share|improve this question

























  • Your question is not clear. Please post a Minimal, Complete, and Verifiable example, including the input and the expected output. -- In general, you can use xsl:number to control how the current node is numbered.

    – michael.hor257k
    Nov 19 '18 at 12:31











  • More information added

    – Luca
    Nov 19 '18 at 12:50











  • But the input is not well-formed XML. And it has no E1EDT13 element, so your template does not match anything. Please refer again to: Minimal, Complete, and Verifiable example.

    – michael.hor257k
    Nov 19 '18 at 12:52













  • E1EDT13 element added

    – Luca
    Nov 19 '18 at 12:58











  • And the input is still not well-formed XML (no root element). And now I have exhausted the time I am willing to spend on this.

    – michael.hor257k
    Nov 19 '18 at 13:08














0












0








0








This is my XML input that I have to transform:



<_-FOX_-SHPMNT06>
<IDOC BEGIN="1">
<E1EDT20 SEGMENT="1">
<TKNUM>8201333969</TKNUM>
<TPBEZ>FDC Domestic YT</TPBEZ`
<E1EDL20 SEGMENT="1">
<VBELN>3460011248</VBELN>
<E1EDT13 SEGMENT="1">
<QUALF>015</QUALF>
<NTANF>20181016</NTANF>
<NTANZ>000000</NTANZ>
<NTEND>20181016</NTEND>
<NTENZ>000000</NTENZ>
<ISDD>00000000</ISDD>
<ISDZ>000000</ISDZ>
<IEDD>00000000</IEDD>
<IEDZ>000000</IEDZ>
</E1EDT13>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z022</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Der Unterzeichner erklärt, dass die in diesem Dokument aufgeführten</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>Waren Ursprungserzeugnisse aus China sind und im Präferenzverkehr mit</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>CH-EU entsprechen.</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
</E1TXTP8>
</E1TXTH8>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z024</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Ihre Artikelnr. 0068018</TDLINE>
</E1TXTP8>
</E1TXTH8>
</E1EDL20>
</E1EDT20>
</IDOC>
</_-FOX_-SHPMNT06>


and this is what I need as XML result:



<_-FOX_-SHPMNT06>
<IDOC BEGIN="1">
<E1EDT20 SEGMENT="1">
<TKNUM>8201333969</TKNUM>
<TPBEZ>FDC Domestic YT</TPBEZ>
<E1EDL20 SEGMENT="1">
<VBELN>3460011248</VBELN>
<E1TXTH8 SEGMENT="1">
<TDOBJECT/>
<TDOBNAME/>
<TDID/>
<TDSPRAS/>
<LANGUA_ISO/>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 01 E Der Unterzeichner erklärt, dass die in diesem Dokument aufgeführten</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 02 E Waren Ursprungserzeugnisse aus China sind und im Präferenzverkehr mit</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 03 E CH-EU entsprechen.</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 04 E </TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 05 E Ihre Artikelnr. 0068018</TDLINE>
</E1TXTP8>
</E1TXTH8>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z022</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Der Unterzeichner erklärt, dass die in diesem Dokument aufgeführten</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>Waren Ursprungserzeugnisse aus China sind und im Präferenzverkehr mit</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>CH-EU entsprechen.</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
</E1TXTP8>
</E1TXTH8>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z024</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Ihre Artikelnr. 0068018</TDLINE>
</E1TXTP8>
</E1TXTH8>
</E1EDL20>
</E1EDT20>
</IDOC>
</_-FOX_-SHPMNT06>


I need to get a global counter instead of using "position()" because I don't want the counter to reset to 0 in every "for-each":



<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<!-- Identity template : copy all text nodes, elements and attributes -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="E1EDT13[position()=last()]">
<E1TXTH8 SEGMENT="1">
<TDOBJECT/>
<TDOBNAME/>
<TDID/>
<TDSPRAS/>
<LANGUA_ISO/>
<xsl:for-each select="following-sibling::E1TXTH8[TDID='Z002']/E1TXTP8">
<E1TXTP8 SEGMENT="1">
<xsl:variable name="typeA">A</xsl:variable>
<TDFORMAT/>
<TDLINE>
<xsl:value-of select="concat('@', ' ', format-number(position(),'00'), ' ', $typeA, ' ', TDLINE)"/>
</TDLINE>
</E1TXTP8>
</xsl:for-each>
<xsl:for-each select="following-sibling::E1TXTH8[TDID='Z022']/E1TXTP8">
<E1TXTP8 SEGMENT="1">
<xsl:variable name="typeE">E</xsl:variable>
<TDFORMAT/>
<TDLINE>
<xsl:value-of select="concat('@', ' ', format-number(position(),'00'), ' ', $typeE, ' ', TDLINE)"/>
</TDLINE>
</E1TXTP8>
</xsl:for-each>
<xsl:for-each select="following-sibling::E1TXTH8[TDID='Z024']/E1TXTP8">
<E1TXTP8 SEGMENT="1">
<xsl:variable name="typeE">E</xsl:variable>
<TDFORMAT/>
<TDLINE>
<xsl:value-of select="concat('@', ' ', format number(position(),'00'), ' ', $typeE, ' ', TDLINE)"/>
</TDLINE>
</E1TXTP8>
</xsl:for-each>
</E1TXTH8>
</xsl:template>
</xsl:stylesheet>


Is there any way to manage it ? If I use "position()" the counters will be 01 02 03 04 01 and I need 01 02 03 04 05 even if I have more "for each"










share|improve this question
















This is my XML input that I have to transform:



<_-FOX_-SHPMNT06>
<IDOC BEGIN="1">
<E1EDT20 SEGMENT="1">
<TKNUM>8201333969</TKNUM>
<TPBEZ>FDC Domestic YT</TPBEZ`
<E1EDL20 SEGMENT="1">
<VBELN>3460011248</VBELN>
<E1EDT13 SEGMENT="1">
<QUALF>015</QUALF>
<NTANF>20181016</NTANF>
<NTANZ>000000</NTANZ>
<NTEND>20181016</NTEND>
<NTENZ>000000</NTENZ>
<ISDD>00000000</ISDD>
<ISDZ>000000</ISDZ>
<IEDD>00000000</IEDD>
<IEDZ>000000</IEDZ>
</E1EDT13>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z022</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Der Unterzeichner erklärt, dass die in diesem Dokument aufgeführten</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>Waren Ursprungserzeugnisse aus China sind und im Präferenzverkehr mit</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>CH-EU entsprechen.</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
</E1TXTP8>
</E1TXTH8>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z024</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Ihre Artikelnr. 0068018</TDLINE>
</E1TXTP8>
</E1TXTH8>
</E1EDL20>
</E1EDT20>
</IDOC>
</_-FOX_-SHPMNT06>


and this is what I need as XML result:



<_-FOX_-SHPMNT06>
<IDOC BEGIN="1">
<E1EDT20 SEGMENT="1">
<TKNUM>8201333969</TKNUM>
<TPBEZ>FDC Domestic YT</TPBEZ>
<E1EDL20 SEGMENT="1">
<VBELN>3460011248</VBELN>
<E1TXTH8 SEGMENT="1">
<TDOBJECT/>
<TDOBNAME/>
<TDID/>
<TDSPRAS/>
<LANGUA_ISO/>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 01 E Der Unterzeichner erklärt, dass die in diesem Dokument aufgeführten</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 02 E Waren Ursprungserzeugnisse aus China sind und im Präferenzverkehr mit</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 03 E CH-EU entsprechen.</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 04 E </TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT/>
<TDLINE>@ 05 E Ihre Artikelnr. 0068018</TDLINE>
</E1TXTP8>
</E1TXTH8>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z022</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Der Unterzeichner erklärt, dass die in diesem Dokument aufgeführten</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>Waren Ursprungserzeugnisse aus China sind und im Präferenzverkehr mit</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDLINE>CH-EU entsprechen.</TDLINE>
</E1TXTP8>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
</E1TXTP8>
</E1TXTH8>
<E1TXTH8 SEGMENT="1">
<TDOBJECT>VBBK</TDOBJECT>
<TDOBNAME>3460011248</TDOBNAME>
<TDID>Z024</TDID>
<TDSPRAS>D</TDSPRAS>
<LANGUA_ISO>DE</LANGUA_ISO>
<E1TXTP8 SEGMENT="1">
<TDFORMAT>*</TDFORMAT>
<TDLINE>Ihre Artikelnr. 0068018</TDLINE>
</E1TXTP8>
</E1TXTH8>
</E1EDL20>
</E1EDT20>
</IDOC>
</_-FOX_-SHPMNT06>


I need to get a global counter instead of using "position()" because I don't want the counter to reset to 0 in every "for-each":



<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<!-- Identity template : copy all text nodes, elements and attributes -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="E1EDT13[position()=last()]">
<E1TXTH8 SEGMENT="1">
<TDOBJECT/>
<TDOBNAME/>
<TDID/>
<TDSPRAS/>
<LANGUA_ISO/>
<xsl:for-each select="following-sibling::E1TXTH8[TDID='Z002']/E1TXTP8">
<E1TXTP8 SEGMENT="1">
<xsl:variable name="typeA">A</xsl:variable>
<TDFORMAT/>
<TDLINE>
<xsl:value-of select="concat('@', ' ', format-number(position(),'00'), ' ', $typeA, ' ', TDLINE)"/>
</TDLINE>
</E1TXTP8>
</xsl:for-each>
<xsl:for-each select="following-sibling::E1TXTH8[TDID='Z022']/E1TXTP8">
<E1TXTP8 SEGMENT="1">
<xsl:variable name="typeE">E</xsl:variable>
<TDFORMAT/>
<TDLINE>
<xsl:value-of select="concat('@', ' ', format-number(position(),'00'), ' ', $typeE, ' ', TDLINE)"/>
</TDLINE>
</E1TXTP8>
</xsl:for-each>
<xsl:for-each select="following-sibling::E1TXTH8[TDID='Z024']/E1TXTP8">
<E1TXTP8 SEGMENT="1">
<xsl:variable name="typeE">E</xsl:variable>
<TDFORMAT/>
<TDLINE>
<xsl:value-of select="concat('@', ' ', format number(position(),'00'), ' ', $typeE, ' ', TDLINE)"/>
</TDLINE>
</E1TXTP8>
</xsl:for-each>
</E1TXTH8>
</xsl:template>
</xsl:stylesheet>


Is there any way to manage it ? If I use "position()" the counters will be 01 02 03 04 01 and I need 01 02 03 04 05 even if I have more "for each"







xslt-1.0






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 13:25







Luca

















asked Nov 19 '18 at 11:31









LucaLuca

12




12













  • Your question is not clear. Please post a Minimal, Complete, and Verifiable example, including the input and the expected output. -- In general, you can use xsl:number to control how the current node is numbered.

    – michael.hor257k
    Nov 19 '18 at 12:31











  • More information added

    – Luca
    Nov 19 '18 at 12:50











  • But the input is not well-formed XML. And it has no E1EDT13 element, so your template does not match anything. Please refer again to: Minimal, Complete, and Verifiable example.

    – michael.hor257k
    Nov 19 '18 at 12:52













  • E1EDT13 element added

    – Luca
    Nov 19 '18 at 12:58











  • And the input is still not well-formed XML (no root element). And now I have exhausted the time I am willing to spend on this.

    – michael.hor257k
    Nov 19 '18 at 13:08



















  • Your question is not clear. Please post a Minimal, Complete, and Verifiable example, including the input and the expected output. -- In general, you can use xsl:number to control how the current node is numbered.

    – michael.hor257k
    Nov 19 '18 at 12:31











  • More information added

    – Luca
    Nov 19 '18 at 12:50











  • But the input is not well-formed XML. And it has no E1EDT13 element, so your template does not match anything. Please refer again to: Minimal, Complete, and Verifiable example.

    – michael.hor257k
    Nov 19 '18 at 12:52













  • E1EDT13 element added

    – Luca
    Nov 19 '18 at 12:58











  • And the input is still not well-formed XML (no root element). And now I have exhausted the time I am willing to spend on this.

    – michael.hor257k
    Nov 19 '18 at 13:08

















Your question is not clear. Please post a Minimal, Complete, and Verifiable example, including the input and the expected output. -- In general, you can use xsl:number to control how the current node is numbered.

– michael.hor257k
Nov 19 '18 at 12:31





Your question is not clear. Please post a Minimal, Complete, and Verifiable example, including the input and the expected output. -- In general, you can use xsl:number to control how the current node is numbered.

– michael.hor257k
Nov 19 '18 at 12:31













More information added

– Luca
Nov 19 '18 at 12:50





More information added

– Luca
Nov 19 '18 at 12:50













But the input is not well-formed XML. And it has no E1EDT13 element, so your template does not match anything. Please refer again to: Minimal, Complete, and Verifiable example.

– michael.hor257k
Nov 19 '18 at 12:52







But the input is not well-formed XML. And it has no E1EDT13 element, so your template does not match anything. Please refer again to: Minimal, Complete, and Verifiable example.

– michael.hor257k
Nov 19 '18 at 12:52















E1EDT13 element added

– Luca
Nov 19 '18 at 12:58





E1EDT13 element added

– Luca
Nov 19 '18 at 12:58













And the input is still not well-formed XML (no root element). And now I have exhausted the time I am willing to spend on this.

– michael.hor257k
Nov 19 '18 at 13:08





And the input is still not well-formed XML (no root element). And now I have exhausted the time I am willing to spend on this.

– michael.hor257k
Nov 19 '18 at 13:08












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373729%2fglobal-counter-xslt-1-0%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373729%2fglobal-counter-xslt-1-0%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)