Created
December 9, 2011 21:39
-
-
Save vicmortelmans/1453419 to your computer and use it in GitHub Desktop.
XSLT to turn YQL Open Table "csv" output with <row>s and <col>s into semantically structured XML based on title row
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 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
version="1.0"> | |
<xsl:template match="/"> | |
<rows> | |
<xsl:apply-templates select="//row"/> | |
</rows> | |
</xsl:template> | |
<xsl:template match="row[position() > 1]"> | |
<xsl:element name="row"> | |
<xsl:apply-templates mode="col"/> | |
</xsl:element> | |
</xsl:template> | |
<xsl:template match="row|diagnostics"/> | |
<xsl:template match="*" mode="col"> | |
<xsl:variable name="position"> | |
<xsl:value-of select="position()"/> | |
</xsl:variable> | |
<xsl:variable name="header"> | |
<xsl:value-of select="../../row[1]/*[name(.) = name(current())]"/> | |
</xsl:variable> | |
<xsl:if test="$header != ''"> | |
<xsl:element name="{translate($header,' ','_')}"> | |
<xsl:value-of select="."/> | |
</xsl:element> | |
</xsl:if> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment