Problem converting XML with XSLT to another XML

H

H. Kaya

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>
 
S

Soren Kuula

H. Kaya said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top