Formatting an XSLT Document
I have an XSLT file to transform data from a table into INSERT statements. So the result looks like
INSERT INTO some_table VALUES (Voda, Šenov);
INSERT INTO some_table VALUES (Vorba, Vlčnov);
which is good for me. My XSLT contains 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's the question, I really don't want to put so many values in one row (my table has 20 columns) to support formatting in the output, just how can I keep the output of the same and my columns in INSERT across multiple rows in for-each
?
Thanks a lot for the answers
EDIT
I would like to have a loop for-each
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>
+3
source to share
1 answer
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 spies 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);
+5
source to share