I have a java application that reads csv file and displays the data on a text area. the idea is to transform this data(source data) into a target data, this involves rearranging it and transforming some elements in each field. now i intend to transform this displayed csv data into an XML block and write an XSLT transformation rules to transform it. the first task is to convert this csv data into XML block. Anyone care to point me to the right direction? do i need to add a couple of classes to my application for this reason?

thank you very much mikeIsme, they helped.. i am now in the XSLT aspect and would need help. i am suppose to write a generic transformation rules with XSLT to transform xml data to another form... meaning tranforming the values to conform to the target data.

If you give me the input xml, and the wanted output xml, highlighting what changes; that can be done.

Edited 4 Years Ago by Mike Askew

this is my xml data

<XMLCreators>

<row>
<RateNumber>1</RateNumber>
<RateLetter>Null</RateLetter>
<AssessmentStreet>Abesinia Passage</AssessmentStreet>
<RateAccomDesc>Dwelling  (Part Of)</RateAccomDesc>
</row>

<row>
<RateNumber>1a</RateNumber>
<RateLetter>Null</RateLetter>
<AssessmentStreet>Arena's Palace Lane</AssessmentStreet>
<RateAccomDesc>Edmund's Home</RateAccomDesc>
</row>
</XMLCreators>

i want a result that would produce this

<Rowinfo>

  <Locator>1</Locator>

  <LocatorDesignator>(RateLetter) (RateAccomDesc) </LocatorDesignator>

  <thoroughfare>Abesinia Passage</thoroughfare>
  <AddressArea>Abesinia Passage</AddressArea>

  <LocatorName>Dwelling  (Part Of)</LocatorName>
</Rowinfo>
<Rowinfo>

  <Locator>1a</Locator>

  <LocatorDesignator>(RateLetter) (RateAccomDesc)</LocatorDesignator>

  <thoroughfare>Arena's Palace Lane</thoroughfare>
  <AddressArea>Arena's Palace Lane</AddressArea>

  <LocatorName>Edmund's Home</LocatorName>

 </Rowinfo>
 </Address>

i have succeeded in getting that but my problem is concatenation
(RateLetter) and (RateAccomDesc) values into a new child element of the row (LocatorDesignator)...... ive been studying loads of materials but i dont seem to get it. please i am in desperate need of your help.
these are my codes so far,

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes" method="xml"/> 
<xsl:template match="/">
    <Address>  <xsl:apply-templates/> </Address>
</xsl:template>

<xsl:template match="row">
    <Rowinfo> <xsl:apply-templates/> </Rowinfo>

</xsl:template>  

      <xsl:template match="AssessmentStreet">
          <xsl:element name="thoroughfare">
         <xsl:value-of select="AssessmentStreet"/> 
        <xsl:apply-templates/> 
    </xsl:element>
    <xsl:element name="AddressArea">
        <xsl:value-of select="AssessmentStreet"/>
        <xsl:apply-templates/>
    </xsl:element>

 </xsl:template>


 <xsl:template match="RateNumber">
    <Locator> <xsl:apply-templates/> </Locator>

</xsl:template>

<xsl:template match="RateAccomDesc">
    <LocatorName> <xsl:apply-templates/> </LocatorName>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
  <xsl:output indent="yes" method="xml"/>
  <xsl:strip-space elements ="*"/>

  <xsl:template match="/">
    <Address>
      <xsl:apply-templates/>
    </Address>
  </xsl:template>

  <xsl:template match="row">
    <xsl:element name="Rowinfo">

      <xsl:element name="Locator">
        <xsl:value-of select="RateNumber"/>
      </xsl:element>

      <xsl:element name="LocatorDesignator">
        <xsl:value-of select ="concat(RateLetter, concat(', ',RateAccomDesc))"/>
      </xsl:element>

      <xsl:element name="thoroughfare">
        <xsl:value-of select="AssessmentStreet"/>
      </xsl:element>

      <xsl:element name="AddressArea">
        <xsl:value-of select="AssessmentStreet"/>
      </xsl:element>

      <xsl:element name="LocatorName">
        <xsl:value-of select="RateAccomDesc"/>
      </xsl:element>

    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

Redid the style sheet slightly, this way allows access to all data within each row when the template is called, else we would need to store the row data in a variable each time.

Feel free to remove the second concatenation as you see fit, the comma seemed to be right considering the output.

With this stylesheet and the above input I get:

<?xml version="1.0" encoding="utf-8"?>
<Address>
  <Rowinfo>
    <Locator>1</Locator>
    <LocatorDesignator>Null, Dwelling (Part Of)</LocatorDesignator>
    <thoroughfare>Abesinia Passage</thoroughfare>
    <AddressArea>Abesinia Passage</AddressArea>
    <LocatorName>Dwelling (Part Of)</LocatorName>
  </Rowinfo>
  <Rowinfo>
    <Locator>1a</Locator>
    <LocatorDesignator>Null, Edmund's Home</LocatorDesignator>
    <thoroughfare>Arena's Palace Lane</thoroughfare>
    <AddressArea>Arena's Palace Lane</AddressArea>
    <LocatorName>Edmund's Home</LocatorName>
  </Rowinfo>
</Address>
Comments
Perfectly Solved
This article has been dead for over six months. Start a new discussion instead.