Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT / XML Iteration

Status
Not open for further replies.

June1975

Programmer
Jul 22, 2003
35
GB
I am trying to use an XSLT to get an XML syntax as shown below. (Where we have repeating Company and Nationality elements per Indes Counter)

I am using News.xml and the att files. can some one help - thanks

<EventDate>30 June 2008
<Title>ATL 1102, clinical data (phase II)
<Indication>multiple sclerosis
<Company>Antisense Therapeutics
<Nationality>Australia
<Company>Teva
<Nationality>Israel

-------------XSLT------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
xmlns:xsl=" version="1.0">

<xsl:eek:utput method="xml" indent="yes"/>

<xsl:template match="/DrugNews">
<xsl:apply-templates select="Report"/>
</xsl:template>

<xsl:template match="Report">

<EventDate> <xsl:value-of select="EventTable/EventRow/EventDate"/> </EventDate>
<Title> <xsl:value-of select="Title"/> </Title>

<xsl:for-each select="Indexes/Index">
<Indic> <xsl:value-of select="IndicatedFor/Indication"/> </Indic>
<Company> <xsl:value-of select="Corporations/Corporation/Company"/> </Company>
<Nationality> <xsl:value-of select="Corporations/Corporation/Nationality"/> </Nationality>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

--------------------XML------------------
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="08MyStyleSheet.xsl"?>
<DrugNews>
<Report Key="134708" Status="Major" ReportType="NR">
<PublicationDate CCYYMMDD="20080714">14 July 2008</PublicationDate>
<Title>ATL 1102, clinical data (phase II)</Title>
<Text>On 30 June 2008 Teva and Antisense Therapeutics announced results from a randomized, double-blind, placebo-controlled, European phase IIa trial of ATL 1102 in 77 patients with relapsing-remitting multiple sclerosis (RRMS). ATL 1102 given at 200 mg three times weekly for the first week and twice weekly for seven additional weeks showed a significant 54.4% decrease in the cumulative number of new active brain lesions (determined using magnetic resonance imaging) compared with placebo, the primary study endpoint, at weeks 4, 8 and 12 (p=0.01). Patients given ATL 1102 also showed a significant 65% decrease in the cumulative number of gadolinium-enhancing lesions at weeks 4, 8 and 12 (p=0.0053) and a significant 84% decrease in T1-enhancing lesion volume at week 12. ATL 1102 showed an increasing effect with time on the reduction of new active lesions over 12 weeks (one month after completing dosing). ATL 1102 was generally well tolerated; potentially attributable adverse events included thrombocytopenia and mild-to-moderate injection-site reactions. Thrombocytopenia returned to normal ranges after interruption of treatment, and was not associated with any clinical consequences. Based on the results obtained in the trial, Teva intends to conduct additional preclinical and clinical research before progressing to a phase III trial. ....ATL 1102, a second-generation antisense oligonucleotide, is being developed for the potential treatment of MS. ATL 1102 inhibits CD 49d, a subunit of VLA-4 (very late antigen-4).</Text>
<EventTable>
<EventRow>
<EventText>clinical data (phase II)</EventText>
<EventDate>30 June 2008</EventDate>
</EventRow>
</EventTable>
<Indexes>
<Index Counter="1">
<Drug Key="2018210">ATL 1102</Drug>
<Corporations>
<Corporation>
<Company>Antisense Therapeutics</Company>
<Nationality>Australia</Nationality>
</Corporation>
</Corporations>
<ReportEvent EventSequence="0" Key="clinical data (phase II)">clinical data (phase II)</ReportEvent>
<ReportEventDate CCYYMMDD="20080630">30 June 2008</ReportEventDate>
<Relationship Code="3">Licensee</Relationship>
<IndicatedFor>
<Indication>multiple sclerosis</Indication>
</IndicatedFor>
</Index>
<Index Counter="2">
<Drug Key="2018210">ATL 1102</Drug>
<Corporations>
<Corporation>
<Company>Teva</Company>
<Nationality>Israel</Nationality>
</Corporation>
</Corporations>
<ReportEvent EventSequence="0" Key="clinical data (phase II)">clinical data (phase II)</ReportEvent>
<ReportEventDate CCYYMMDD="20080630">30 June 2008</ReportEventDate>
<Relationship Code="5">Sub-licensee</Relationship>
<IndicatedFor>
<Indication>multiple sclerosis</Indication>
</IndicatedFor>
</Index>
</Indexes>
</Report>
<Report Key="134709" Status="Minor" ReportType="GN">
<PublicationDate CCYYMMDD="20080714">14 July 2008</PublicationDate>
<Title>metformin + vildagliptin, marketed</Title>
<Text>During May 2008, Novartis launched EUCREAS, a fixed combination oral tablet formulation of vildagliptin, a dipeptidyl peptidase IV inhibitor, combined with metformin, in Germany. The agent is indicated for the treatment of type II diabetes mellitus and is also marketed in Brazil, the UK and Finland.</Text>
<EventTable>
<EventRow>
<EventText>marketed, Germany</EventText>
<EventDate>May 2008</EventDate>
</EventRow>
</EventTable>
<Indexes>
<Index Counter="3">
<Drug Key="2029345">metformin + vildagliptin</Drug>
<Corporations>
<Corporation>
<Company>Novartis</Company>
<Nationality>Switzerland</Nationality>
</Corporation>
</Corporations>
<ReportEvent EventSequence="7" Key="pc Launch">marketed</ReportEvent>
<ReportEventDate CCYYMMDD="20080501" Qualifier="M">May 2008</ReportEventDate>
<Relationship Code="1">Developer</Relationship>
<IndicatedFor>
<Indication>diabetes</Indication>
</IndicatedFor>
<AppliesToRegion>
<Region>Germany</Region>
</AppliesToRegion>
</Index>
</Indexes>
</Report>
<Report Key="134710" Status="Major" ReportType="NR">
<PublicationDate CCYYMMDD="20080714">14 July 2008</PublicationDate>
<Title>Lev plans to file for European marketing authorization (HAE)</Title>
<Text>Lev announced on 1 July 2008 that it has entered into a letter agreement with Sanquin authorizing Lev to file for European marketing authorization for C1-esterase inhibitor (C1-INH;CINRYZE) for the treatment of hereditary angioedema (HAE). Lev has received notification from the EMEA that it is eligible to submit an application for Community Marketing Authorization for CINRYZE through the centralized European registration procedure. Lev plans to submit the application to the EMEA fourth quarter 2008. ....Purified human C1-INH, a C1-esterase inhibitor, human plasma protein, is being developed by Lev for the iv treatment of HAE and acute myocardial infarction.</Text>
<Indexes>
<Index Counter="4">
<Drug Key="2024065">CINRYZE</Drug>
<Corporations>
<Corporation>
<Company>Lev</Company>
<Nationality>USA</Nationality>
</Corporation>
</Corporations>
<ReportEvent EventSequence="0" Key="general">general</ReportEvent>
<ReportEventDate CCYYMMDD="20080701">1 July 2008</ReportEventDate>
<Relationship Code="3">Licensee</Relationship>
</Index>
</Indexes>
</Report>
<Report Key="134711" Status="Major" ReportType="NR">
<PublicationDate CCYYMMDD="20080714">14 July 2008</PublicationDate>
<Title>lodamin, preclinical data</Title>
<Text>On 30 June 2008, researchers at the Children's Hospital Boston (USA) reported preclinical data on lodamin, a broad-spectrum angiogenesis inhibitor, for the potential treatment of cancer and age-related macular degeneration (AMD). In mouse models of melanoma and lung cancer, lodamin selectively accumulated in tumor tissue, inhibited angiogenesis, and significantly inhibited primary tumor growth with a significantly prolonged half-life. No side effects were observed when used at effective doses. Lodamin accumulated in the liver (without toxicity), preventing liver metastases and prolonging survival in mice. The agent was effective against a range of tumors in mice, including breast cancer, neuroblastoma, ovarian cancer, prostate cancer, glioblastomas and uterine tumors. ....Lodamin is a slow-release reformulation of TNP 470, an angiogenesis inhibitor originally isolated from Aspergillus fumigatus fresenius, which was discontinued because of neurological side effects. Lodamin employs nanotechnology in order to attach stable polymeric micelles to TNP 470, thereby protecting the agent from the stomach's acidity. SynDevRx has in-licensed the agent from the Children's Hospital Boston, the primary pediatric teaching hospital of Harvard Medical School (USA).</Text>
<EventTable>
<EventRow>
<EventText>preclinical data</EventText>
<EventDate>30 June 2008</EventDate>
</EventRow>
</EventTable>
<Indexes>
<Index Counter="5">
<Drug Key="2030951">lodamin</Drug>
<Corporations>
<Corporation>
<Company>Boston Childrens Hospital</Company>
<Nationality>USA</Nationality>
</Corporation>
</Corporations>
<ReportEvent EventSequence="0" Key="preclinical data">preclinical data</ReportEvent>
<ReportEventDate CCYYMMDD="20080630">30 June 2008</ReportEventDate>
<Relationship Code="1">Licensor</Relationship>
<NewDrug>Yes</NewDrug>
</Index>
</Indexes>
</Report>
<Report Key="134712" Status="Major" ReportType="NR">
<PublicationDate CCYYMMDD="20080714">14 July 2008</PublicationDate>
<Title>omacetaxine mepesuccinate, submitted for approval</Title>
<Text>On 1 July 2008 ChemGenex announced that it has submitted the non-clinical section of the rolling submission of an NDA to the US FDA for omacetaxine mepesuccinate as a treatment for chronic myeloid leukemia (CML). The next submission will be the chemistry and manufacturing controls (CMC) section, due first half 2009, followed by the clinical section, which ChemGenex plans to submit to complete the filing mid 2009. ....Omacetaxine mepesuccinate, a natural product which acts as a potent apoptosis inducer and angiogenesis inhibitor, has potential utility in the treatment of various hematological cancers, including acute promyelocytic leukemia (APL) and CML.</Text>
<EventTable>
<EventRow>
<EventText>submitted for approval, USA</EventText>
<EventDate>1 July 2008</EventDate>
</EventRow>
</EventTable>
<Indexes>
<Index Counter="6">
<Drug Key="2016454">omacetaxine mepesuccinate</Drug>
<Corporations>
<Corporation>
<Company>ChemGenex</Company>
<Nationality>Australia</Nationality>
</Corporation>
</Corporations>
<ReportEvent EventSequence="4" Key="pc Pre-reg">submitted for approval</ReportEvent>
<ReportEventDate CCYYMMDD="20080701">1 July 2008</ReportEventDate>
<Relationship Code="1">Developer</Relationship>
<IndicatedFor>
<Indication>CML</Indication>
</IndicatedFor>
<AppliesToRegion>
<Region>USA</Region>
</AppliesToRegion>
<NewPhase>Yes</NewPhase>
</Index>
</Indexes>
</Report>
</DrugNews>
 
Not sure how generic the sample xml and sample output reflect the need. As such, it can be understood in more than one way. This is one way to do it.
[tt]
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
xmlns:xsl="[ignore][/ignore]"
version="1.0">
<xsl:eek:utput method="xml" indent="yes" />

<xsl:template match="/DrugNews">
<xsl:apply-templates select="Report"/>
</xsl:template>

<xsl:template match="Report">
<xsl:element name="EventDate">
<xsl:value-of select="EventTable/EventRow/EventDate"/>
</xsl:element>
<xsl:element name="Title">
<xsl:value-of select="Title"/>
</xsl:element>
<xsl:apply-templates select="Indexes" />
</xsl:template>

<xsl:template match="Indexes">
<xsl:apply-templates select="Index[count(preceding-sibling::Index[IndicatedFor/Indication])=0]" mode="U" />
</xsl:template>

<xsl:template match="Index" mode="U">
<xsl:element name="Indic">
<xsl:value-of select="IndicatedFor/Indication"/>
</xsl:element>
<xsl:for-each select="self::* | following-sibling::Index[IndicatedFor/Indication]">
<xsl:element name="Company">
<xsl:value-of select="Corporations/Corporation/Company"/>
</xsl:element>
<xsl:element name="Nationality">
<xsl:value-of select="Corporations/Corporation/Nationality"/>
</xsl:element>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
[/tt]
Since the unique heading "Indication" comes from deep child nodes of the xml, I would use a less efficient approach rather than using xsl:key element. It would here be more effective. You can look into this alternative yourslef if you like.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top