Skip to content

Instantly share code, notes, and snippets.

@slowkow
Last active August 29, 2015 14:13
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 slowkow/63f9c7dc369b5fa02830 to your computer and use it in GitHub Desktop.
Save slowkow/63f9c7dc369b5fa02830 to your computer and use it in GitHub Desktop.
Transform Biosample XML to TSV.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" />
<!--
Transform biosample XML to TSV.
Usage: xsltproc biosample2tsv.xsl input.xml > output.tsv
-->
<xsl:template match="/">GEO<xsl:text>&#x9;</xsl:text>Title<xsl:text>&#x9;</xsl:text>CellLine<xsl:text>&#x9;</xsl:text>CellType<xsl:text>&#x9;</xsl:text>CdnaMethod<xsl:text>&#10;</xsl:text>
<xsl:for-each select="//BioSample">
<!-- GEO Id -->
<xsl:value-of select="//Id[@db='GEO']" />
<xsl:text>&#x9;</xsl:text>
<!-- Title -->
<xsl:if test="//Description/Title">
<xsl:value-of select="//Description/Title" />
</xsl:if>
<xsl:text>&#x9;</xsl:text>
<!-- Tab character
<xsl:text>&#x9;</xsl:text>
-->
<!-- Cell Line -->
<xsl:choose>
<xsl:when test="//Attribute[@attribute_name='cell line']">
<xsl:value-of select="//Attribute[@attribute_name='cell line']" />
</xsl:when>
<xsl:otherwise>NA</xsl:otherwise>
</xsl:choose>
<xsl:text>&#x9;</xsl:text>
<!-- Cell Type -->
<xsl:choose>
<xsl:when test="//Attribute[@attribute_name='cell type']">
<xsl:value-of select="//Attribute[@attribute_name='cell type']" />
</xsl:when>
<xsl:otherwise>NA</xsl:otherwise>
</xsl:choose>
<xsl:text>&#x9;</xsl:text>
<!-- CDNA Method -->
<xsl:choose>
<xsl:when test="//Attribute[@attribute_name='cdna synthesis method']">
<xsl:value-of select="//Attribute[@attribute_name='cdna synthesis method']" />
</xsl:when>
<xsl:otherwise>NA</xsl:otherwise>
</xsl:choose>
<!-- New line -->
<xsl:text>&#10;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment