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"
xmlns

sl="http://www.w3.org/1999/XSL/Transform">
<xsl

utput 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>);
</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>);
</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.