I have an XSLT file for transforming data from table to INSERT statements. So the output looks like
INSERT INTO some_table VALUES (Voda, Šenov);
INSERT INTO some_table VALUES (Vorba, Vlčnov);
which is fine to me. My XSLT contains this three lines
<xsl:for-each select="PAGE/ROWSET/ROW">
INSERT INTO some_table VALUES (<xsl:value-of select="SURNAME"/>, <xsl:value-of select="CITY"/>);
</xsl:for-each>
And here is the question, I really dont want to put so many values on the same line(my table has like 20 columns) in order to maintain the formatting in output, so is there a way how to keep output the same and have my columns in INSERT on multiple lines in for-each?
Thanks a lot for answers
EDIT
I would like to have the for-each loop like this
<xsl:for-each select="PAGE/ROWSET/ROW">
INSERT INTO some_table VALUES va1 ,val2 (
<xsl:value-of select="SURNAME"/>,
<xsl:value-of select="CITY"/>);
</xsl:for-each>
Try
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="1.0" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:for-each select="PAGE/ROWSET/ROW">
<xsl:text>INSERT INTO some_table VALUES val1 ,val2 (</xsl:text>
<xsl:value-of select="SURNAME"/><xsl:text>, </xsl:text>
<xsl:value-of select="CITY"/><xsl:text>);</xsl:text>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
In XML Spy, with input
<?xml version="1.0" encoding="UTF-8"?>
<PAGE>
<ROWSET>
<ROW>
<SURNAME>sn1</SURNAME>
<CITY>c1</CITY>
</ROW>
<ROW>
<SURNAME>sn2</SURNAME>
<CITY>c2</CITY>
</ROW>
</ROWSET>
</PAGE>
I get
INSERT INTO some_table VALUES val1 ,val2 (sn1, c1);
INSERT INTO some_table VALUES val1 ,val2 (sn2, c2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With