[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Borut, with your CML input, the following XSL
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<NewDataSet>
<xsl:for-each select="DataSet/Table[Level = 1]">
<xsl:variable name="next1" select="./following-sibling::*[1]"/>
<Transport name="${Description}">
<xsl:for-each select="following-sibling::Table[Level = 2 and not(./following-sibling::Table = $next1)]">
<Brand name="${Description}">
</Brand>
</xsl:for-each>
</Transport>
</xsl:for-each>
</NewDataSet>
</xsl:template>
</xsl:stylesheet>
produces:
I'm sure you can work out how to extend this to include models.
Regards,
--A
_________________________________________________________________
Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/
RE: [xsl] flat XML to normal XML
Subject: RE: [xsl] flat XML to normal XML From: "Aron Bock" <aronbock@xxxxxxxxxxx> Date: Mon, 16 May 2005 13:54:39 +0000 |
Borut, with your CML input, the following XSL
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<NewDataSet>
<xsl:for-each select="DataSet/Table[Level = 1]">
<xsl:variable name="next1" select="./following-sibling::*[1]"/>
<Transport name="${Description}">
<xsl:for-each select="following-sibling::Table[Level = 2 and not(./following-sibling::Table = $next1)]">
<Brand name="${Description}">
</Brand>
</xsl:for-each>
</Transport>
</xsl:for-each>
</NewDataSet>
</xsl:template>
</xsl:stylesheet>
produces:
<NewDataSet> <Transport name="$Cars"> <Brand name="$BMW"/> <Brand name="$Citroen"/> <Brand name="$Alfa Romeo"/> </Transport> <Transport name="$Motorcycles"/> </NewDataSet>
I'm sure you can work out how to extend this to include models.
Regards,
--A
From: Borut BolDina <bob@xxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] flat XML to normal XML Date: Mon, 16 May 2005 12:24:45 +0200
Hello list,
I wish to transform an xml which has level information in each item (Table) to xml which has hierarchy as stated in those item's element.
<DataSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Table> <Level>1</Level> <Description>Cars</Description> </Table> <Table> <Level>2</Level> <Description>BMW</Description> </Table> <Table> <Level>3</Level> <Description>316</Description> </Table> <Table> <Level>3</Level> <Description>Z4</Description> </Table> <Table> <Level>2</Level> <Description>Citroen</Description> </Table> <Table> <Level>3</Level> <Description>C2</Description> </Table> <Table> <Level>3</Level> <Description>C4 coupe</Description> </Table> <Table> <Level>2</Level> <Description>Alfa Romeo</Description> </Table> <Table> <Level>3</Level> <Description>156</Description> </Table> <Table> <Level>1</Level> <Description>Motorcycles</Description> </Table> ... ... </DataSet>
Target xml should look something like this:
<NewDataSet> <Transport name="Cars"> <Brand name="BMW"> <Model>316</Model> <Model>Z4</Model> </Brand> <Brand name="Citroen"> <Model>C2</Model> <Model>C4 coupe</Model> </Brand> <Brand name="Alfa Romeo"> <Model>156</Model> </Brand> </Transport> <Transport name="Motorcycle"> ... </Transport> </NewDataSet>
_________________________________________________________________
Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Suppressing Newline Chara, David Carlisle | Thread | RE: [xsl] flat XML to normal XML, Aron Bock |
Re: [xsl] For-each loop or recursio, Oleg Konovalov | Date | [xsl] end-tag minimization problem?, Mikael Petterson \(K |
Month |
Keywords