Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > need some help with xsl / xml

Reply
Thread Tools

need some help with xsl / xml

 
 
Mr_Noob
Guest
Posts: n/a
 
      12-17-2007
Hi all,

here is a sample on my xml file :

<systems>
<controllers>
<id>1</id>
<name>controller1</name>
<memory>4096</memory>
<hosts>
<id>1</id>
<name>host1</name>
<memory>256</memory>
<id>2</id>
<name>host2</name>
<memory>256</memory>
</hosts>
<id>2</id>
<name>controller2</name>
<memory>4096</memory>
</controllers>
</systems>

I am trying to write an xsl stylesheet that would generate the
following output :

insert into controllers (name, memory) values (controller1, 4096);
insert into hosts (id, name, memory, controller_id) values (1, host1,
256, 1);
insert into hosts (id, name, memory, controller_id) values (2, host2,
256, 1);
insert into controllers (name, memory) values (controlle2, 4096);

Here is the xsl i've written so far :

<?xml version="1.0" ?>
<xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput method="text"/>
<xsl:template match="systems">
<xsl:template match="controllers">
insert into controllers (name, memory) values (<xsl:value-of
select="name"/> , <xsl:value-of select="memory"/>);
<xsl:template match="hosts">
insert into hosts (id, name, memory, controller_id) values (<xsl:value-
of select="id"/> , <xsl:value-of select="name"/>, <xsl:value-of
select="memory"/> , <xsl:value-of select="CONTROLLER_Id?"/>);
</xsl:template>
</xsl:template>
</xsl:template>
</xsl:stylesheet>

well as you can see, i don't know how to do such a thing....

any idea?

 
Reply With Quote
 
 
 
 
Pavel Lepin
Guest
Posts: n/a
 
      12-17-2007

Mr_Noob <> wrote in
<73433e65-5b6a-449b-9641->:
> <systems>
> <controllers>
> <id>1</id>
> <name>controller1</name>
> <memory>4096</memory>
> <hosts>
> <id>1</id>
> <name>host1</name>
> <memory>256</memory>
> <id>2</id>
> <name>host2</name>
> <memory>256</memory>
> </hosts>
> <id>2</id>
> <name>controller2</name>
> <memory>4096</memory>
> </controllers>
> </systems>


Bloody awful. Why don't you structure your XML documents
properly?

<systems>
<controllers>
<controller id="1" name="foo" mem="4096">
<hosts>
<host id="1" name="baz" mem="256"/>
<host id="2" name="quux" mem="256"/>
</hosts>
</controller>
<controller id="2" name="bar" mem="4096"/>
</controllers>
</systems>

> I am trying to write an xsl stylesheet that would generate
> the following output...


<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="text"/>
<xsl:template match="controllers|hosts">
<xsl:apply-templates select="id"/>
</xsl:template>
<xsl:template match="controllers/id">
<xsl:text>INSERT INTO controllers </xsl:text>
<xsl:text>(id,name,memory) values (</xsl:text>
<xsl:value-of select="number(text())"/>
<xsl:text>,'</xsl:text>
<xsl:value-of
select="following-sibling::name[1]/text()"/>
<xsl:text>',</xsl:text>
<xsl:value-of
select=
"
number(following-sibling::memory[1]/text())
"/>
<xsl:text>);&#x0a;</xsl:text>
<xsl:apply-templates
select="following-sibling::hosts[1]"/>
</xsl:template>
<xsl:template match="hosts/id">
<xsl:text>INSERT INTO hosts </xsl:text>
<xsl:text>(id,name,memory,controller_id) </xsl:text>
<xsl:text>values (</xsl:text>
<xsl:value-of select="number(text())"/>
<xsl:text>,'</xsl:text>
<xsl:value-of
select="following-sibling::name[1]/text()"/>
<xsl:text>',</xsl:text>
<xsl:value-of
select=
"
number(following-sibling::memory[1]/text())
"/>
<xsl:text>,</xsl:text>
<xsl:value-of
select=
"
number(../preceding-sibling::id[1]/text())
"/>
<xsl:text>);&#x0a;</xsl:text>
</xsl:template>
</xsl:stylesheet>

--
....also, I submit that we all must honourably commit seppuku
right now rather than serve the Dark Side by producing the
HTML 5 spec.
 
Reply With Quote
 
 
 
 
Mr_Noob
Guest
Posts: n/a
 
      12-17-2007

> Bloody awful. Why don't you structure your XML documents
> properly?


I agree, bloody awful indeed. This XML document is generated
automatically , I have to deal with it

Thanks a lot for your help
 
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
Please help to write an xsl which converts src xml to dest xml ramadevimandala XML 0 04-16-2009 10:14 AM
XML to XML using XSL. Please, help me! Thank You! shapper ASP .Net 2 11-19-2006 03:22 AM
Help with XSL/XSL:FO for producing revision indicator bar in document. =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?= XML 6 05-03-2006 02:46 PM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
Need help with xml and xsl design Adam Wasi XML 0 09-01-2003 12:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57