Problem converting XML with XSLT to another XML

Discussion in 'XML' started by H. Kaya, Feb 13, 2004.

  1. H. Kaya

    H. Kaya Guest

    Hallo,

    I have a problem converting a XML file to a other. I have no idea how
    I can do this. I try it for a long time but I can not find a solution.
    Has anyone a Idea?
    Below you can find my Input XML Document, Output XML Document and my
    scratch XSLT file. At the end is my request Output XML.

    Greetings H. Kaya

    My last scratch xslt:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="xml"/>

    <xsl:key name="kDistinctCarDealer" match="CARDEALER" use="."/>
    <xsl:key name="kDistinctCity" match="CITY" use="."/>

    <xsl:template match="/">
    <xsl:for-each select="ROWSET/ROW/CITY[generate-id() =
    generate-id(key('kDistinctCity',.))]">
    <xsl:apply-templates select = ".." />
    </xsl:for-each>
    </xsl:template>

    <xsl:template match="CARDEALER">
    <xsl:text disable-output-escaping="yes">
    &lt;CARDEALERS&gt;</xsl:text>
    <xsl:for-each select="/ROWSET/ROW/CARDEALER[generate-id() =
    generate-id(key('kDistinctCarDealer',.))]">
    <xsl:copy-of select="."/>
    </xsl:for-each>
    <xsl:text disable-output-escaping="yes">
    &lt;/CARDEALERS&gt;</xsl:text>
    </xsl:template>

    </xsl:stylesheet>

    It Produce following output:

    <?xml version="1.0" encoding="UTF-8"?>

    HAMBURG
    DATA2
    DATA3
    DATA4
    DATA5
    <CARDEALERS><CARDEALER> FORD </CARDEALER><CARDEALER> BMW
    </CARDEALER><CARDEALER> VW </CARDEALER> </CARDEALERS>

    BERLIN
    DATA6
    DATA7
    DATA8
    DATA9
    <CARDEALERS><CARDEALER> FORD </CARDEALER><CARDEALER> BMW
    </CARDEALER><CARDEALER> VW </CARDEALER> </CARDEALERS>


    My input look like this:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <ROWSET>
    <ROW num="1">
    <CITY> HAMBURG </CITY>
    <COL2> DATA2 </COL2>
    <COL3> DATA3 </COL3>
    <COL4> DATA4 </COL4>
    <COL5> DATA5 </COL5>
    <CARDEALER> FORD </CARDEALER>
    </ROW>
    <ROW num="2">
    <CITY> HAMBURG </CITY>
    <COL2> DATA2 </COL2>
    <COL3> DATA3 </COL3>
    <COL4> DATA4 </COL4>
    <COL5> DATA5 </COL5>
    <CARDEALER> BMW </CARDEALER>
    </ROW>
    <ROW num="3">
    <CITY> HAMBURG </CITY>
    <COL2> DATA2 </COL2>
    <COL3> DATA3 </COL3>
    <COL4> DATA4 </COL4>
    <COL5> DATA5 </COL5>
    <CARDEALER> VW </CARDEALER>
    </ROW>
    <ROW num="4">
    <CITY> BERLIN </CITY>
    <COL2> DATA6 </COL2>
    <COL3> DATA7 </COL3>
    <COL4> DATA8 </COL4>
    <COL5> DATA9 </COL5>
    <CARDEALER> FORD </CARDEALER>
    </ROW>
    <ROW num="5">
    <CITY> BERLIN </CITY>
    <COL2> DATA6 </COL2>
    <COL3> DATA7 </COL3>
    <COL4> DATA8 </COL4>
    <COL5> DATA9 </COL5>
    <CARDEALER> BMW </CARDEALER>
    </ROW>
    <ROW num="6">
    <CITY> BERLIN </CITY>
    <COL2> DATA6 </COL2>
    <COL3> DATA7 </COL3>
    <COL4> DATA8 </COL4>
    <COL5> DATA9 </COL5>
    <CARDEALER> VW </CARDEALER>
    </ROW>
    </ROWSET>



    The output should look like this:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <ROWSET>
    <ROW num="1">
    <CITY> BERLIN </CITY>
    <COL2> DATA2 </COL2>
    <COL3> DATA3 </COL3>
    <COL4> DATA4 </COL4>
    <COL5> DATA5 </COL5>
    <CARDEALERS>
    <CARDEALER> FORD </CARDEALER>
    <CARDEALER> BMW </CARDEALER>
    <CARDEALER> VW </CARDEALER>
    </CARDEALERS>
    <ROW num="2">
    <CITY> BERLIN </CITY>
    <COL2> DATA6 </COL2>
    <COL3> DATA7 </COL3>
    <COL4> DATA8 </COL4>
    <COL5> DATA9 </COL5>
    <CARDEALERS>
    <CARDEALER> FORD </CARDEALER>
    <CARDEALER> BMW </CARDEALER>
    <CARDEALER> VW </CARDEALER>
    </CARDEALERS>
    </ROW>
    </ROWSET>
     
    H. Kaya, Feb 13, 2004
    #1
    1. Advertising

  2. H. Kaya

    Soren Kuula Guest

    H. Kaya wrote:
    > Hallo,
    >
    > I have a problem converting a XML file to a other. I have no idea how
    > I can do this. I try it for a long time but I can not find a solution.
    > Has anyone a Idea?


    You need a program to do do that, such as xlstproc (Linux) or Java1.4
    (built into Java 1.4, available at Apache.org for older Javas).

    Decide for one (I'd say the Java is easier) and when you have got it,
    return here for specifics.

    Soren

    --
    Fjern de 4 bogstaver i min mailadresse som er indsat for at hindre s...
    Remove the 4 letter word meaning "junk mail" in my mail address.
     
    Soren Kuula, Feb 13, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. loveNUNO
    Replies:
    2
    Views:
    934
    loveNUNO
    Nov 20, 2003
  2. nanookfan
    Replies:
    2
    Views:
    576
    Martin Honnen
    Jan 14, 2004
  3. Replies:
    0
    Views:
    513
  4. jkflens
    Replies:
    2
    Views:
    1,500
    jkflens
    May 30, 2006
  5. Replies:
    18
    Views:
    2,768
    Joseph Kesselman
    Oct 4, 2006
Loading...

Share This Page