I am using following XSLT to form the XML and the code is working fine but I want this code to be wrapped under a condition.
In the following XML since S_HL/D_735='T' appearing only once that's why I dont want the code to be executed.
If G_HL[S_HL/D_735 ='T'] exists more than 1 in the source xml then only the following code should be executed otherwise not required.
Source XML
<?xml version="1.0" encoding="UTF-8"?>
<M_856>
<S_ST>
<D_143>856</D_143>
<D_329>0001</D_329>
</S_ST>
<S_BSN>
<D_353>00</D_353>
<D_396>0080000055</D_396>
<D_373>20240123</D_373>
<D_337>040849</D_337>
<D_1005>0001</D_1005>
</S_BSN>
<G_HL>
<S_HL>
<D_628/>
<D_734/>
<D_735>S</D_735>
</S_HL>
<S_TD5>
<D_66>2</D_66>
<D_67>0BP070A</D_67>
<D_91>M</D_91>
</S_TD5>
</G_HL>
<G_HL>
<S_HL>
<D_628/>
<D_734/>
<D_735>O</D_735>
</S_HL>
</G_HL>
<G_HL>
<S_HL>
<D_628/>
<D_734/>
<D_735>I</D_735>
</S_HL>
<S_LIN>
<D_350>000010</D_350>
<D_235>BP</D_235>
</S_LIN>
</G_HL>
<G_HL>
<S_HL>
<D_628/>
<D_734/>
<D_735>I</D_735>
</S_HL>
<S_LIN>
<D_350>000020</D_350>
<D_235>BP</D_235>
</S_LIN>
</G_HL>
<G_HL>
<S_HL>
<D_628/>
<D_734/>
<D_735>T</D_735>
</S_HL>
<S_PO4>
<D_82>0.000</D_82>
<D_350>000010</D_350>
</S_PO4>
</G_HL>
<G_HL>
<S_HL>
<D_628/>
<D_734/>
<D_735>I</D_735>
</S_HL>
<S_LIN>
<D_350>000030</D_350>
<D_235>BP</D_235>
</S_LIN>
</G_HL>
<G_HL>
<S_HL>
<D_628/>
<D_734/>
<D_735>I</D_735>
</S_HL>
<S_LIN>
<D_350>000040</D_350>
<D_235>BP</D_235>
</S_LIN>
</G_HL>
<S_CTT>
<D_354>B2B_LIN_COUNTER</D_354>
</S_CTT>
</M_856>
XSLT 2.0 Getting stylesheet compilation error now after adding If condition
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<!-- Identity template to copy nodes as-is -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="G_HL[S_HL/D_735='T' and S_PO4/D_350 = following::G_HL[S_HL/D_735='I']/S_LIN/D_350]">
<xsl:copy-of select="."/>
<xsl:if test="count(//G_HL/S_HL/[D_735='T']) ge 2)">
<xsl:copy-of select="following::G_HL[S_HL/D_735='I' and S_LIN/D_350 = current()/S_PO4/D_350]"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
I am not sure I have understood the complete problem but as we are struggling to interchange code in comments or in the chat I post a working sample:
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<!-- Identity template to copy nodes as-is -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="G_HL[S_HL/D_735='T' and S_PO4/D_350 = following::G_HL[S_HL/D_735='I']/S_LIN/D_350]">
<xsl:copy-of select="."/>
<xsl:if test="count(//G_HL[S_HL/D_735 ='T']) ge 2">
<xsl:copy-of select="following::G_HL[S_HL/D_735='I' and S_LIN/D_350 = current()/S_PO4/D_350]"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
This is "working" in terms of counting and in terms of not giving syntax errors, the whole problem is not quite clear so far, as to which part of the input you want to further process or include depending on that count and why you have put further conditions in your code unrelated to the count and not explained in the textual description.