Jump to content

using 2 conditions with children of same parents..


smandape

Recommended Posts

<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><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>I want the values which has the attribute match for 'generif' at the same time i want to check if Gene-commentary_text exists, if this is true then do the for-each over and give me the output. I tried "and" but I think I am not putting it at its correct place. The following is the XSLT code..Boen_robot helped me to satisfy the first condition but i am unable to satisfy the second condition...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> <field name="gene_function"> <xsl:if test="./Gene-commentary[Gene-commentary_type/@value=generif' and Gene-commentary_text='.]"> <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> </xsl:if> </field>I also tried many other ways like <xsl:if test="Entrezgene_comments/Gene-commentary/Gene-commentary_type/@value='generif' and Entrezgene_comments/Gene-commentary[string(Gene-commentary_type/@value)=generif]/Gene-commentary_text='.'>Could u please help me..Thank you,Sammed..

Link to comment
Share on other sites

What people often forget to clarify, and I suppose the reason I didn't told you anything the first time, is what happens when the thing at hand doesn't exist.If you want to simply not output the text and the comma that would follow it if it was there, i.e. not do:

<xsl:value-of select="Gene-commentary_text"/>,

Then you can simply have it like:

<xsl:if test="Gene-commentary_text"><xsl:value-of select="Gene-commentary_text"/>,</xsl:if>

but if it's a little more complicated than that, you'll have to be a little more specific... like, give example output for one thing.

Link to comment
Share on other sites

Thank you Boen_robot for reply. Well, I think I didn't put the question in correct frame...I want to satisfy two conditions at the same time...I want to extract the <Gene-commentary_text> when <Gene-commentary_type value="generif">, ie @value="generif", and when <Gene-commentary_text> exists...this is so because at the end of the XML code there exists <Gene-commentary_type value="generif"> but <Gene-commentary_text> does not exists and so at the end of my output I get blank with an extra',' and ':' which I am unable to get rid of...The end of my output looks something like thisglycan-specific oxidoreductase ERp57 was cross-linked to type I membrane glycoprotein tyrosinase when calnexin and calreticulin were associated,15958486;,;</field>Here the first two lines are the ones I need, but they should be the last one as seen in XML code. Only because there exists <Gene-commentary_type value="generif"> at the end but not <Gene-commentary_text>, it gives me blank with ',' and ';'.I hope I have rephrased my question correctly...Could you help me..Thank you,Sammed

Link to comment
Share on other sites

Hello Boen_robot..well, i forgot to mention One thing..which can rephrase the question in most appropriate manner...i am trying not to get ',' and ';' for the last value that I extract..so I was trying to use<xsl:if test="position() != last()"> condition..I got what you want to say...I used the code such that I don't get blank ',' and ';' at the end..but i thought it would also be there for the last value that I extract..the output I get is as follows:No genetic susceptibility or increased risk attributed to the tyrosinase gene family in Vogt-Koyanagi-Harada disease in Japanese., 17200659;tyrosinase has a role in progression of melanoma, 17496783;tyrosinase has a role in progression of metastatic melanoma, 17496782;glycan-specific oxidoreductase ERp57 was cross-linked to type I membrane glycoprotein tyrosinase when calnexin and calreticulin were associated, 15958486;but I am trying to get it as follows:No genetic susceptibility or increased risk attributed to the tyrosinase gene family in Vogt-Koyanagi-Harada disease in Japanese., 17200659;tyrosinase has a role in progression of melanoma, 17496783;tyrosinase has a role in progression of metastatic melanoma, 17496782;glycan-specific oxidoreductase ERp57 was cross-linked to type I membrane glycoprotein tyrosinase when calnexin and calreticulin were associated, 15958486Anyway, I changed some of the formats and now my professor is asking to add some more things in it..so I got what I want..I am sorry to bother you a lot about this..and I thank you for your support till now..Thank you,Sammed

Link to comment
Share on other sites

If I sound like I'm being "bothered", it's because you don't make enough sence, and I want to avoid pointing you in a wrong direction.I never really got why you need the condition around the for-each. The for-each is not going to be executed even once if there are no nodes matching it.Also, if you want to exclude something from the loop, you need to alter the expression by which you gather all nodes... the idea of for-each is that you have a certain set of things for which you do something. Conditions within the loop are only necesarily if a certain piece needs to be processed in a slightly different fashion, but still in the same order. Not the case here.You can chain predicates in an XPath expression together in order to limit the set of nodes to loop over. In your case, you have two conditions - that the element has a Gene-commentary_type child element with a "value" attribute having the value 'generif' and you want a Gene-commentary_text to be present.Here's one way to chain it

<field name="gene_function"> <xsl:for-each select="Entrezgene_comments/Gene-commentary[string(Gene-commentary_type/@value)='generif'][Gene-commentary_text]"> <xsl:value-of select="Gene-commentary_text"/>, <xsl:value-of select="Gene-commentary_refs/Pub/Pub_pmid/PubMedId"/>;</xsl:for-each></field>

and here's another:

<field name="gene_function"> <xsl:for-each select="Entrezgene_comments/Gene-commentary[string(Gene-commentary_type/@value)='generif' and boolean(Gene-commentary_text)]"> <xsl:value-of select="Gene-commentary_text"/>, <xsl:value-of select="Gene-commentary_refs/Pub/Pub_pmid/PubMedId"/>;</xsl:for-each></field>

The output should be the same, with one of these being potentially quicker, depending on your XSLT processor.

Link to comment
Share on other sites

Thank you Boen_robot. I got it now. I understood what you said. Thank you for your concern. Well, here is something I am trying to do with the XML code below:

<Gene-commentary_type value="comment">254</Gene-commentary_type>            <Gene-commentary_heading>Pathways</Gene-commentary_heading>            <Gene-commentary_comment>                <Gene-commentary>                    <Gene-commentary_type value="comment">254</Gene-commentary_type>                    <Gene-commentary_text>KEGG pathway: Melanogenesis</Gene-commentary_text>

I want to extract the <Gene-commentary_text> after the ':',ie, i just want 'Melanogenesis'.I used the following XSLT code:

<field name="Pathways"><xsl:for-each select="Entrezgene_comments/Gene-commentary[string(Gene-commentary_heading)='Pathways']/Gene-commentary_comment/Gene-commentary">					<field name="Pathway_name"><xsl:value-of select="Gene-commentary_text[substring-after(text(),':')]"/> </field></xsl:for-each> </field>I also tried <field name="Pathway_name"><xsl:value-of select="Gene-commentary_text[substring-after(.,':')]"/>

Thank you for your help..Thank you,Sammed

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...