Subject: RE: [xsl] Manipulating elements depending on the existence of sub-elements From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Wed, 12 Mar 2008 12:01:23 -0400 |
Try something like this:
<xsl:template match="/" <xsl:apply-templates select="//UniqueInfo"/> </xsl:template>
<xsl:template match="UniqueInfo"> <transaction> <xsl:apply-templates select="../preceding-sibling::transaction[not(UniqueInfo)]/line | ../line"/> </transaction> </xsl:template>
<Transaction which="A"> <Line>...</Line> <Line>...</Line> </Transaction> <Transaction which="B"> <Line>...</Line> <Line>...</Line> </Transaction> <Transaction which="C"> <Line>...</Line> <Line>...</Line> <UniqueInfo>...</UniqueInfo> </Transaction> <Transaction which="D"> <Line>...</Line> <Line>...</Line> </Transaction> <Transaction which="E"> <Line>...</Line> <Line>...</Line> <UniqueInfo>...</UniqueInfo> </Transaction>
<xsl:template match="UniqueInfo"> <transaction> <xsl:apply-templates select="key('Lines-for-UniqueInfo',generate-id())"/> </transaction> </xsl:template>
Alternatively, what I often advise people when handling dirty data: write two transformations and run them in series (a pipeline). The first one is to clean up the data, the second is to transform it. One benefit is that when you fix the data supplier to stop generating dirty data, you can throw out the first stylesheet. Another benefit is that the clean-up stylesheet will be reusable when you want to process the dirty data in a different way.
Cheers, Wendell
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Manipulating elements dep, Adil Ladhani | Thread | Re: [xsl] Manipulating elements dep, Adil Ladhani |
Re: [xsl] Manipulating elements dep, Wendell Piez | Date | [xsl] Count preceding cousins and s, Jim_Albright |
Month |