I have a below for-each loop in my XSLT which gives me concatenated string of distinct values of CUST_PO_NUMBER from input XML
<xsl:key name="custpo"
match="LIST_G_DELV/G_DELV/LIST_G_INV_LINES/G_INV_LINES"
use="CUST_PO_NUMBER"/>
<xsl:template match="XXFIN_GBL_RAINV_PRINT">
<xsl:apply-templates select="LIST_G_INV"/>
</xsl:template>
<xsl:template match="LIST_G_INV">
<xsl:for-each select="G_INV">
<xsl:value-of select="CUSTOMER_TRX_ID"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="substring(LIST_G_SEB/G_SEB/SEB_NAME,1,255)"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="substring(IDM_BILL_TO_CUSTOMER_NAME,1,255)"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="BILL_TO_CUSTOMER_NUMBER"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="TRX_NUMBER"/>
<xsl:text>|</xsl:text>
<xsl:for-each select="LIST_G_DELV/G_DELV/LIST_G_INV_LINES/G_INV_LINES[generate-id()=generate-id(key('custpo',CUST_PO_NUMBER)[1])]">
<xsl:value-of select="CUST_PO_NUMBER"/>
<xsl:if test="not(position() = last())">
<xsl:text>;</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>|</xsl:text>
<xsl:value-of select="CUST_ISO_LANGUAGE"/>
</xsl:for-each>
</xsl:template>
Ultimately output of this XSLT is CSV file (seperated by pipe | ). Can we just truncate result of for-each loop on CUST_PO_NUMBER element to 1000 characters?
I believe this should work if you replace the following
for-each:with:
and since you’d be using a
substring()anyway, you can eliminate theifandtextby doing this: