Thread: Resolved Going from XML to SQL
View Single Post
Old 12-02-2012, 08:37 AM   PM User | #1
TheLostOne
New to the CF scene

 
Join Date: Dec 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
TheLostOne is an unknown quantity at this point
Going from XML to SQL

I have been trying my hand lately at trying to convert an xml file to SQL complient text file. I was told about XSLT and have been trying very hard but, as my username reveals, I am lost

I started researching and tried modifying the code found here but to no avail. Here is what my modification came out to look like right now:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:template match="/">
<html>
	<head />
	<body title="The Holy Bible">
		<xsl:for-each select="bible">
			<p>
				<xsl:for-each select="book">
					<xsl:if test="position( )=1">
						<table border="1">
							<thead>
								<tr>
										<td>Book</td>
										<td>Chapter</td>
										<td>Verse</td>
								</tr>
							</thead>
							<tbody>
								<xsl:for-each select="../book">
									<tr>
										<td>
											<xsl:for-each select="@name">
												<xsl:value-of select="." />
											</xsl:for-each>
										</td>
									</tr>
								</xsl:for-each>
							</tbody>
						</table>
					</xsl:if>
				</xsl:for-each>
			</p>
		</xsl:for-each>
	</body>
</html>
</xsl:template>
</xsl:stylesheet>
I really do not know what to do about this for the code is not working as I would like. I want to output to look something like this:

Code:
INSERT INTO "bibletable" ("book", "chapter", "verse", "text") VALUES ('Genesis', 1, 1, 'In the beginning . . .');
INSERT INTO "bibletable" ("book", "chapter", "verse", "text") VALUES ('Genesis', 1, 2, 'And the earth was without form . . .');
...
...
INSERT INTO "bibletable" ("book", "chapter", "verse", "text") VALUES ('Revelation', 22, 20, 'He which testifieth these things . . .');
INSERT INTO "bibletable" ("book", "chapter", "verse", "text") VALUES ('Revelation', 22, 21, 'The grace of our Lord . . .');
Now if I cannot get it exactly like this I at least want to get as close as possible and I will use regex to do the rest.

Can you please offer me some advice? I would really like it.

If you want more info just say so. But, I hope this is sufficient to deliver the message.

Last edited by TheLostOne; 12-03-2012 at 11:06 PM.. Reason: Solved!
TheLostOne is offline   Reply With Quote