Selecting data with same node name and merging data from XML file -
i'm trying select data uniprot xml file, , i'm able things want out, i'm having problems getting data out have more entries in same node. , preferably combine them together.
xml code:
<?xml version='1.0' encoding='utf-8'?> <?xml-stylesheet href="test_will7.xslt" type="text/xsl" ?> <uniprot> <entry dataset="swiss-prot" created="1993-04-01" modified="2012-11-28" version="118"> <accession>p30443</accession> <accession>o77964</accession> <name>1a01_human</name> <protein> <recommendedname> <fullname>hla class histocompatibility antigen, a-1 alpha chain</fullname> </recommendedname> </protein> <gene> <name type="primary">hla-a</name> <name type="synonym">hlaa</name> </gene> </comment> <comment type="subcellular location"> <subcellularlocation> <location>membrane</location> <topology>single-pass type membrane protein</topology> </subcellularlocation> </comment> <dbreference type="go" id="go:0031901"> <property type="term" value="c:early endosome membrane"/> <property type="evidence" value="tas:reactome"/> </dbreference> <dbreference type="go" id="go:0012507"> <property type="term" value="c:er golgi transport vesicle membrane"/> <property type="evidence" value="tas:reactome"/> </dbreference> <dbreference type="go" id="go:0000139"> <property type="term" value="c:golgi membrane"/> <property type="evidence" value="tas:reactome"/> </dbreference> </entry> <entry dataset="swiss-prot" created="1986-07-21" modified="2012-11-28" version="151"> <accession>p01892</accession> <accession>o19619</accession> <accession>p06338</accession> <name>1a02_human</name> <protein> <recommendedname> <fullname>hla class histocompatibility antigen, a-2 alpha chain</fullname> </recommendedname> </protein> <gene> <name type="primary">hla-a</name> <name type="synonym">hlaa</name> </gene> <comment type="subcellular location"> <subcellularlocation> <location>membrane</location> <topology>single-pass type membrane protein</topology> </subcellularlocation> </comment> <dbreference type="go" id="go:0060333"> <property type="term" value="p:interferon-gamma-mediated signaling pathway"/> <property type="evidence" value="tas:reactome"/> </dbreference> </entry> <entry dataset="swiss-prot" created="1987-08-13" modified="2012-11-28" version="124"> <accession>p04439</accession> <name>1a03_human</name> <protein> <recommendedname> <fullname>hla class histocompatibility antigen, a-3 alpha chain</fullname> </recommendedname> </protein> <gene> <name type="primary">hla-a</name> <name type="synonym">hlaa</name> </gene> <comment type="subcellular location"> <subcellularlocation> <location>membrane</location> <topology>single-pass type membrane protein</topology> </subcellularlocation> </comment> <dbreference type="go" id="go:0005887"> <property type="term" value="c:integral plasma membrane"/> <property type="evidence" value="nas:uniprotkb"/> </dbreference> <dbreference type="go" id="go:0019048"> <property type="term" value="p:virus-host interaction"/> <property type="evidence" value="iea:uniprotkb-kw"/> </dbreference> </entry> </uniprot>
and xslt file looks this. however, i'm still doing wrong, since doesn't work. maybe because of different levels?
<?xml version="1.0" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:template match="/"> <html> <body> <h2>my selection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>name</th> <th>genename</th> <th>accessionnr</th> <th>proteinname</th> <th>subcellularlocation</th> <th>tissuespecificity</th> <th>goid</th> <th>goname</th> </tr> <xsl:apply-templates/> </table> </body> </html> </xsl:template> <xsl:template match="uniprot/entry"> <tr> <xsl:apply-templates select="name|gene/name|accession|protein/recommendedname/fullname|comment[@type = 'subcellular location']/subcellularlocation/location|comment[@type = 'tissue specificty']/text|dbreference[@type = 'go']/@id|dbreference[@type = 'go']/property[@type = 'term']/@value"/> </tr> </xsl:template> <xsl:template match="name|gene/name|accession|protein/recommendedname/fullname|comment[@type = 'subcellular location']/subcellularlocation/location|comment[@type = 'tissue specificty']/text|dbreference[@type = 'go']/@id|dbreference[@type = 'go']/property[@type = 'term']/@value"> <xsl:choose> <xsl:when test="name()='dbreference[@type = 'go']/@id|dbreference[@type = 'go']/property[@type = 'term']/@value' , not(preceding-sibling::dbreference[@type = 'go']/@id|dbreference[@type = 'go']/property[@type = 'term']/@value)"> <td> <xsl:value-of select="."/> <xsl:if test="following-sibling::dbreference[@type = 'go']/@id|dbreference[@type = 'go']/property[@type = 'term']/@value"> <xsl:text>;</xsl:text> <xsl:for-each select="following-sibling::dbreference[@type = 'go']/@id|dbreference[@type = 'go']/property[@type = 'term']/@value"> <xsl:value-of select="."/> <xsl:if test="position()!=last()"> <xsl:text>;</xsl:text> </xsl:if> </xsl:for-each> </xsl:if> </td> </xsl:when> <xsl:when test="name()='dbreference[@type = 'go']/@id|dbreference[@type = 'go']/property[@type = 'term']/@value' , preceding-sibling::dbreference[@type = 'go']/@id|dbreference[@type = 'go']/property[@type = 'term']/@value"/> <xsl:otherwise> <td> <xsl:value-of select="."/> </td> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
my desired output:
name genename accessionnr proteinname subcellularlocation goid_ goname 1a01_human hla-a p30443 hla class histocompatibility antigen, a-1 alpha chain membrane go:0031901- c:early endosome membrane; go:0012507- c:er golgi transport vesicle membrane; go:0000139- c:golgi membrane 1a02_human hla-a p01892 hla class histocompatibility antigen, a-2 alpha chain membrane go:0060333-p:interferon-gamma-mediated signaling pathway 1a03_human hla-a p04439 hla class histocompatibility antigen, a-3 alpha chain membrane go:0005887- c:integral plasma membrane; go:0019048- p:virus-host interaction
if difficult, might this:
name genename accessionnr proteinname subcellularlocation goid goname 1a01_human hla-a p30443 hla class histocompatibility antigen, a-1 alpha chain membrane go:0031901; go:0012507; go:0000139 c:early endosome membrane; c:er golgi transport vesicle membrane; c:golgi membrane 1a02_human hla-a p01892 hla class histocompatibility antigen, a-2 alpha chain membrane go:0060333 p:interferon-gamma-mediated signaling pathway 1a03_human hla-a p04439 hla class histocompatibility antigen, a-3 alpha chain membrane go:0005887; go:0019048 c:integral plasma membrane; p:virus-host interaction
i know lot, , pretty difficult distinguish everything. can read code, fixing bugs or writing new still difficult! (and i'm new xml) thank you!
i have deleted 'organism' xml input , created new xslt desired output:
xslt:
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:template match="uniprot"> <html> <body> <h2>my selection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>name</th> <th>genename</th> <th>accessionnr</th> <th>proteinname</th> <th>subcellularlocation</th> <th>tissuespecificity</th> <th>goid</th> <th>goname</th> </tr> <xsl:for-each select="entry"> <tr> <td><xsl:value-of select="name"/></td> <td><xsl:value-of select="gene/name"/></td> <td><xsl:value-of select="accession"/></td> <td><xsl:value-of select="protein/recommendedname/fullname"/></td> <td><xsl:value-of select="comment[@type = 'subcellular location']/subcellularlocation/location"/></td> <td><xsl:value-of select="comment[@type = 'tissue specificty']"/></td> <td> <xsl:for-each select="dbreference[@type = 'go']"> <xsl:value-of select="concat(@id,'- ',property[@type = 'term']/@value,'; ')"/> </xsl:for-each> </td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
output:
<html> <body> <h2>my selection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>name</th> <th>genename</th> <th>accessionnr</th> <th>proteinname</th> <th>subcellularlocation</th> <th>tissuespecificity</th> <th>goid</th> <th>goname</th> </tr> <tr> <td>1a01_human</td> <td>hla-a</td> <td>p30443</td> <td>hla class histocompatibility antigen, a-1 alpha chain</td> <td>membrane</td> <td></td> <td>go:0031901- c:early endosome membrane; go:0012507- c:er golgi transport vesicle membrane; go:0000139- c:golgi membrane; </td> </tr> <tr> <td>1a02_human</td> <td>hla-a</td> <td>p01892</td> <td>hla class histocompatibility antigen, a-2 alpha chain</td> <td>membrane</td> <td></td> <td>go:0060333- p:interferon-gamma-mediated signaling pathway; </td> </tr> <tr> <td>1a03_human</td> <td>hla-a</td> <td>p04439</td> <td>hla class histocompatibility antigen, a-3 alpha chain</td> <td>membrane</td> <td></td> <td>go:0005887- c:integral plasma membrane; go:0019048- p:virus-host interaction; </td> </tr> </table> </body> </html>
Comments
Post a Comment