Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Problem converting XML with XSLT to another XML

Reply
Thread Tools

Problem converting XML with XSLT to another XML

 
 
H. Kaya
Guest
Posts: n/a
 
      02-13-2004
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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xslutput 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>
 
Reply With Quote
 
 
 
 
Soren Kuula
Guest
Posts: n/a
 
      02-13-2004
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT question: How to lookup another tag's children in XSLT yinglcs@gmail.com XML 18 10-03-2006 11:22 PM
Problem to insert an XML-element by XSLT-converting from one XML-file into another XML-file jkflens XML 2 05-30-2006 09:41 AM
How to use XSLT to transform XML according to the data in another XML ai2003lian@yahoo.com XML 0 02-02-2005 04:57 PM
Problem converting XML to HTML using XSLT on Netscape 7.0 nanookfan XML 2 01-14-2004 11:09 AM
Using One XSLT and multiple XML Problem (One is XML and another one is XBRL) loveNUNO XML 2 11-20-2003 06:47 AM



Advertisments