Last active
December 15, 2015 00:49
-
-
Save fbaligand/5175606 to your computer and use it in GitHub Desktop.
XSLT permettant de transformer un fichier XML DBUnit en script SQL d'insertion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" encoding="UTF-8" media-type="text/sql"/> | |
<xsl:template match="dataset"> | |
<xsl:apply-templates select="./*"/> | |
</xsl:template> | |
<xsl:template match="dataset/*"> | |
<xsl:text>insert into </xsl:text> | |
<xsl:value-of select="name()"/> | |
<xsl:text> (</xsl:text> | |
<xsl:for-each select="./@*"> | |
<xsl:call-template name="columnName"/> | |
</xsl:for-each> | |
<xsl:text>) values (</xsl:text> | |
<xsl:for-each select="./@*"> | |
<xsl:call-template name="columnValue"/> | |
</xsl:for-each> | |
<xsl:text>); </xsl:text> | |
</xsl:template> | |
<xsl:template name="columnName"> | |
<xsl:value-of select="name()"/> | |
<xsl:if test="position() != last()"> | |
<xsl:text>, </xsl:text> | |
</xsl:if> | |
</xsl:template> | |
<xsl:template name="columnValue"> | |
<xsl:text>'</xsl:text> | |
<xsl:value-of select="."/> | |
<xsl:text>'</xsl:text> | |
<xsl:if test="position() != last()"> | |
<xsl:text>, </xsl:text> | |
</xsl:if> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment