Skip to content

Instantly share code, notes, and snippets.

@fbaligand
Last active December 15, 2015 00:49
Show Gist options
  • Save fbaligand/5175606 to your computer and use it in GitHub Desktop.
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
<?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>);&#13;</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