Skip to content

Instantly share code, notes, and snippets.

@JoshuaCarroll
Created March 29, 2018 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshuaCarroll/d2efe2b9f1f65af39d5665c53e63a16b to your computer and use it in GitHub Desktop.
Save JoshuaCarroll/d2efe2b9f1f65af39d5665c53e63a16b to your computer and use it in GitHub Desktop.
XSL transform to input XML of states and output SQL insert statement
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
<xsl:template match="/states/state">
INSERT INTO States (State, Borders)
VALUES ('<xsl:value-of select="@name"/>', (geography::STGeomFromText('POLYGON((<xsl:for-each select="point"><xsl:value-of select="@lng"/><xsl:text> </xsl:text><xsl:value-of select="@lat"/>,</xsl:for-each><xsl:value-of select="point[1]/@lng"/><xsl:text> </xsl:text><xsl:value-of select="point[1]/@lat"/>))', 4326)));
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment