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">
<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">
<CARDEALERS></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">
</CARDEALERS></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>
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">
<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">
<CARDEALERS></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">
</CARDEALERS></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>