smandape Posted January 16, 2011 Share Posted January 16, 2011 Hello Seniors,I have problem with the following code, kindly help me, please...thank you for your help.<Entrezgene><Gene-commentary> <Gene-commentary_type value="comment">254</Gene-commentary_type> <Gene-commentary_text>UniGene</Gene-commentary_text>Gene-commentary> <Gene-commentary_type value="generif">18</Gene-commentary_type> <Gene-commentary_text>We have identified five different TYR mutations, including one novel mutation, which caused oculocutaneous albinism type 1 in Chinese.</Gene-commentary_text> <Gene-commentary_refs> <Pub> <Pub_pmid> <PubMedId>20447099</PubMedId> </Pub_pmid> </Pub> </Gene-commentary_refs> </Gene-commentary><Gene-commentary> <Gene-commentary_type value="generif">18</Gene-commentary_type> <Gene-commentary_text>observed associations between generalized vitiligo and markers implicating multiple genes, one (TYR) that may mediate target-cell specificity and indicate a mutually exclusive relationship between susceptibility to vitiligo and susceptibility to melanoma</Gene-commentary_text> <Gene-commentary_refs> <Pub> <Pub_pmid> <PubMedId>20410501</PubMedId> </Pub_pmid> </Pub> </Gene-commentary_refs> </Gene-commentary><Gene-commentary> <Gene-commentary_type value="generif">18</Gene-commentary_type> <Gene-commentary_text>T cell receptor transgenic mice are created that recognize an epitope of the melanocyte protein, tyrosinase. These animals develop vitiligo with strikingly similar characteristics to the human disease.</Gene-commentary_text> <Gene-commentary_refs> <Pub> <Pub_pmid> <PubMedId>20083666</PubMedId> </Pub_pmid> </Pub> </Gene-commentary_refs> </Gene-commentary> <Gene-commentary> <Gene-commentary_type value="generif">18</Gene-commentary_type> <Gene-commentary_text>DNA analysis revealed that the patient is a compound heterozygote for mutations in the tyrosinase gene, her genotype confers no apparent cutaneous disease and only mild ocular features.</Gene-commentary_text> <Gene-commentary_refs> <Pub> <Pub_pmid> <PubMedId>20006830</PubMedId> </Pub_pmid> </Pub> </Gene-commentary_refs> </Gene-commentary></Entrezgene>I want to extract the data Gene-commentary_text for the Gene-commentary that has the Gene-commentary_type value='generif' and for that same value I want to extract the gene-commentary_refs/Pub/Pub_pmid/PubMedIDI tried the following XSLT code:<field name="gene_function"> <xsl:if test="Entrezgene_comments/Gene-commentary/Gene-commentary_type/@value='generif'"> <xsl:for-each select="Entrezgene_comments/Gene-commentary"> <xsl:if test="position() != last()"> <xsl:value-of select="Gene-commentary_text"/>, <xsl:value-of select="Gene-commentary_refs/Pub/Pub_pmid/PubMedId"/>; </xsl:if> <xsl:if test="position() = last()"> <xsl:value-of select="Gene-commentary_text"/>, <xsl:value-of select="Gene-commentary_refs/Pub/Pub_pmid/PubMedId"/>; </xsl:if> </xsl:for-each> </xsl:if> The thing is that Entrezgene_comments/Gene-commentary being only one of its kind in the whole file, if I try the above code without xsl:if statement it gives me the same output as with xsl:if statement. But, Gene-commentary_refs/Pub/Pub_pmid/PubMedId being many I am unable to filter based on @value='generif'. I get the duplicate value for "20588308" which I need to filter based on the @value='generif', the first '20588308' does not belong to Gene-commentary_refs/Pub/Pub_pmid/PubMedId I get the following output:<field name="gene_function">, ; , ; , 20588308; , ; , ; , ; , ; We have identified five different TYR mutations, including one novel mutation, which caused oculocutaneous albinism type 1 in Chinese., 20447099; observed associations between generalized vitiligo and markers implicating multiple genes, one (TYR) that may mediate target-cell specificity and indicate a mutually exclusive relationship between susceptibility to vitiligo and susceptibility to melanoma, 20410501; T cell receptor transgenic mice are created that recognize an epitope of the melanocyte protein, tyrosinase. These animals develop vitiligo with strikingly similar characteristics to the human disease., 20083666; DNA analysis revealed that the patient is a compound heterozygote for mutations in the tyrosinase gene, her genotype confers no apparent cutaneous disease and only mild ocular features., 20006830</gene_function>I have tried to put up my problem in the best possible way I can, I hope you would get it.Thank you.Sammed Link to comment Share on other sites More sharing options...
boen_robot Posted January 16, 2011 Share Posted January 16, 2011 The paths you're using are a little too absolute in a way... what you're checking if there's ANY attribute in the XML document matching the condition, and then do the for-each over the whole document if there is. Since you always have something to satisfy the condition, the rest works the same with and without it. If you were to remove all nodes satisfying the condition, the whole for-each would not execute.The best thing you can do is make a predicate on the loop, so that you only loop over certain elements.I'm not exactly sure what you want in the end though... but here's a guess: <field name="gene_function"> <xsl:for-each select="Entrezgene_comments/Gene-commentary[string(Gene-commentary_type/@value)='generif']"> <xsl:if test="position() != last()"> <xsl:value-of select="Gene-commentary_text"/>, <xsl:value-of select="Gene-commentary_refs/Pub/Pub_pmid/PubMedId"/>;</xsl:if> <xsl:if test="position() = last()"> <xsl:value-of select="Gene-commentary_text"/>, <xsl:value-of select="Gene-commentary_refs/Pub/Pub_pmid/PubMedId"/>;</xsl:if> </xsl:for-each> </field> Link to comment Share on other sites More sharing options...
smandape Posted January 16, 2011 Author Share Posted January 16, 2011 Thank you Boen robot. Yes, I am trying to check if there's ANY attribute in the XML document matching the condition, and then do the for-each over the whole document if there is. Thank you once again. I really thank you for providing me the solutions to my problems. This way I am learning many things which help me a lot in my work. I really appreciate your efforts for this forum. Thank you.Sammed Link to comment Share on other sites More sharing options...
smandape Posted January 17, 2011 Author Share Posted January 17, 2011 Hello Boen_robot, along with the above if condition that says I want the values which has the attribute match for 'generif', i want to check if Gene-commentary_text exists then do the for-each over and give me the output how can I do that??? I tried "and" but I think I am not putting it at its correct place.Because at the end of the file the xml code has the following <Gene-commentary> <Gene-commentary_type value="generif">18</Gene-commentary_type> <Gene-commentary_heading>Interactions</Gene-commentary_heading> <Gene-commentary_comment> <Gene-commentary> <Gene-commentary_type value="generif">18</Gene-commentary_type> <Gene-commentary_refs> <Pub> <Pub_pmid> <PubMedId>14623273</PubMedId> </Pub_pmid> </Pub> </Gene-commentary_refs>which gives me the following output, only with ',' and ';'...glycan-specific oxidoreductase ERp57 was cross-linked to type I membrane glycoprotein tyrosinase when calnexin and calreticulin were associated, 15958486; , ; </field>.. could you please, kindly help me.. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.