Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>XSLT transforms a document tree to another document tree. As I know there are no direct connectors to MySQL that could insert transformed data into MYSQL.</p> <p>Another option might be to generate an XML that could be imported by MySQL.</p> <p><code>mysqldump</code> utility accepts --xml option that allows to dump data in XML format (so you can transform your data to the format). Unfortunatelly, loading the data from the file back is a trick that is <a href="http://dev.mysql.com/tech-resources/articles/xml-in-mysql5.1-6.0.html#xml-5.1-importing-sp" rel="nofollow noreferrer">available only from MySQL 5.1</a>. In MySQL 6.0.3 though there appears a new LOAD XML statement that can be used for the purpose.</p> <p>I believe that the task can easily be solved by reading the XML with an XML-reader and inserting the data row by row using standard database connectors in any modern programming language.</p> <p><strong>UPD</strong>:</p> <p>An xsl might look as following:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="text"/&gt; &lt;xsl:template match="breakfast_menu"&gt; &lt;xsl:apply-templates mode="insert-to-food" select="food" /&gt; &lt;xsl:apply-templates mode="insert-to-breakfast_menu" select="food" /&gt; &lt;/xsl:template&gt; &lt;xsl:template mode="insert-to-food" match="food"&gt; &lt;xsl:text&gt;INSERT INTO food(&lt;/xsl:text&gt; &lt;xsl:number /&gt; &lt;xsl:text&gt;, '&lt;/xsl:text&gt; &lt;xsl:value-of select="name" /&gt; &lt;xsl:text&gt;', '&lt;/xsl:text&gt; &lt;xsl:value-of select="price" /&gt; &lt;xsl:text&gt;', '&lt;/xsl:text&gt; &lt;xsl:value-of select="description" /&gt; &lt;xsl:text&gt;', &lt;/xsl:text&gt; &lt;xsl:value-of select="calories" /&gt; &lt;xsl:text&gt;);&amp;#xA;&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;xsl:template mode="insert-to-breakfast_menu" match="food"&gt; &lt;xsl:text&gt;INSERT INTO breakfast_menu(1, &lt;/xsl:text&gt; &lt;xsl:number /&gt; &lt;xsl:text&gt;);&amp;#xA;&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload