How to get comma separated values as the output XSLT 1

Gayara Kumari 65 Reputation points
2023-03-16T11:52:41.01+00:00

Hi Team,

Currently we have a requirement to get comma separated values on XSLT 1.0. Currently we are getting a part of PONumbers as the output. But we need to get all PO numbers. Could you please support on this, for your reference here with attached Current Source sample/ Current XSLT part and Expected output.

Source XML-



Current Sample XSLT Line -

	

Current Output-

4501581467,4501581480,450

Expected Result-

4501581467,4501581480,4501644842

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,542 questions
{count} votes

Accepted answer
  1. Yitzhak Khabinsky 26,586 Reputation points
    2023-03-17T19:04:11.6966667+00:00

    Hi @Gayara Kumari,

    Please try the following solution.

    <?xml version="1.0"?>
    <root>
    	<PONumber>4501581467, 4501581480, 4501644842, 4501581270</PONumber>
    </root>
    
    

    XSLT

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="xml" encoding="utf-8" indent="yes"
    	            omit-xml-declaration="no"/>
    	<xsl:strip-space elements="*"/>
    
    	<xsl:variable name="string" select="/root/PONumber"/>
    	<xsl:variable name="cnt" select="1"/>
    
    	<xsl:template match="/">
    		<OrderNumberCollection>
    			<xsl:call-template name="tokenize">
    				<xsl:with-param name="string" select="$string"/>
    				<xsl:with-param name="delim" select="','"/>
    				<xsl:with-param name="cnt" select="$cnt"/>
    			</xsl:call-template>
    		</OrderNumberCollection>
    	</xsl:template>
    
    	<xsl:template name="tokenize">
    		<xsl:param name="string"/>
    		<xsl:param name="delim"/>
    		<xsl:param name="cnt"/>
    
    		<xsl:choose>
    			<xsl:when test="contains($string, $delim)">
    				<OrderNumber>
    					<Sequence>
    						<xsl:value-of select="$cnt"/>
    					</Sequence>
    					<OrderReference>
    						<xsl:value-of select="normalize-space(substring-before($string, $delim))"/>
    					</OrderReference>
    				</OrderNumber>
    				<xsl:call-template name="tokenize">
    					<xsl:with-param name="string"
    					                select="substring-after($string, $delim)"/>
    					<xsl:with-param name="delim" select="$delim"/>
    					<xsl:with-param name="cnt" select="$cnt+1"/>
    				</xsl:call-template>
    			</xsl:when>
    			<xsl:otherwise>
    				<OrderNumber>
    					<Sequence>
    						<xsl:value-of select="$cnt"/>
    					</Sequence>
    					<OrderReference>
    						<xsl:value-of select="normalize-space($string)"/>
    					</OrderReference>
    				</OrderNumber>
    			</xsl:otherwise>
    		</xsl:choose>
    	</xsl:template>
    </xsl:stylesheet>
    
    

    Output

    <?xml version='1.0' encoding='utf-8' standalone='no' ?>
    <OrderNumberCollection>
      <OrderNumber>
        <Sequence>1</Sequence>
        <OrderReference>4501581467</OrderReference>
      </OrderNumber>
      <OrderNumber>
        <Sequence>2</Sequence>
        <OrderReference>4501581480</OrderReference>
      </OrderNumber>
      <OrderNumber>
        <Sequence>3</Sequence>
        <OrderReference>4501644842</OrderReference>
      </OrderNumber>
      <OrderNumber>
        <Sequence>4</Sequence>
        <OrderReference>4501581270</OrderReference>
      </OrderNumber>
    </OrderNumberCollection>
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.