Skip to Content
avatar image
Former Member

HCI: Need xslt code to convert xml to text.

Hi Experts

Below is my XML after one of my mapping

i need to convert it to text using an xslt code

<?xml version="1.0" encoding="UTF-8"?>
<ns0:FILE xmlns:ns0="http://bc.***.com/FILE">
   <ACCOUNT_ID>1234567</ACCOUNT_ID>
   <CURRENCY>EUR</CURRENCY>
   <BRANCH_ID>1234</BRANCH_ID>
   <TRANSACTION_TYPE>D</TRANSACTION_TYPE>
   <AMOUNT>47.5</AMOUNT>
   <PARTICULARS>2000000023100017</PARTICULARS>
</ns0:FILE>

I want this to be converted like below using xslt.

1234567EUR1234D47.52000000023100017

I need help in writing the xslt code for this one 
Regards
NAINA
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Dec 18, 2017 at 08:45 AM

    Hi Naina!

    XSLT isn't intended for producing text files from XML input. You could achieve it using java or groovy.

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 18, 2017 at 02:58 PM

    Hi Naina

    You can use the xsl:output element to indicate the type of output. Here's a small stylesheet that generates the text string you need:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://bc.***.com/FILE">
        <xsl:output method="text"/>
        <xsl:template match="/">
            <xsl:value-of select="/ns0:FILE/ACCOUNT_ID"/>
            <xsl:value-of select="/ns0:FILE/CURRENCY"/>
            <xsl:value-of select="/ns0:FILE/BRANCH_ID"/>
            <xsl:value-of select="/ns0:FILE/TRANSACTION_TYPE"/>
            <xsl:value-of select="/ns0:FILE/AMOUNT"/>
            <xsl:value-of select="/ns0:FILE/PARTICULARS"/>
        </xsl:template>
    </xsl:stylesheet>
    

    Regards,

    Morten

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 05 at 01:53 PM

    Hi Naina,

    This can be achieved using available standard pallet. You can achieve this like below, no need to go for XSLT mapping.

    1. Use a message mapping to convert your structure like below. Simple concatenate function available in Graphical mapping is enough to achieve this.

    <?xml version="1.0" encoding="UTF-8"?>
    <Record>
    <Text> ACCOUNT_ID+CURRENCY+BRANCH_ID+TRANSACTION_TYPE+AMOUNT+PARTICULARS </Text>
    </Record>

    2. After this step, use XML to CSV converter -

    Path to Source Element in XSD: //Record

    Field Separator in CSV: tab

    Thanks,

    Apu

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 23 at 07:00 AM

    Hi Naina,

    You can use the below XSLT mapping to convert your XML record to Text file.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:output omit-xml-declaration="no" indent="yes" method="text"/>
      <xsl:strip-space elements="*"/>
       <xsl:template match="/">
            <xsl:apply-templates select="//file"/>
        </xsl:template>
        <xsl:template match="ACCOUNT_ID"> 
        <xsl:value-of select="."/>
        </xsl:template>
           <xsl:template match="CURRENCY"> 
        <xsl:value-of select="."/>
        </xsl:template>
           <xsl:template match="BRANCH_ID"> 
        <xsl:value-of select="."/>
        </xsl:template>
        <xsl:template match="TRANSACTION_TYPE"> 
        <xsl:value-of select="."/>
        </xsl:template>
        <xsl:template match="AMOUNT"> 
        <xsl:value-of select="."/>
        </xsl:template>
        <xsl:template match="PARTICULARS"> 
        <xsl:value-of select="."/>
            <xsl:text>
    </xsl:text>
        </xsl:template>
       </xsl:stylesheet>

    Add comment
    10|10000 characters needed characters exceeded