Subject: Re: [xsl] splitting multiple occurrences of an element within another element From: Mukul Gandhi <mukulgw3@xxxxxxxxx> Date: Wed, 24 Sep 2003 11:12:25 -0700 (PDT) |
Hi Brian, Please try the XSL -- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/database"> <database> <xsl:for-each select="document/doclink"> <document> <form> <xsl:value-of select="parent::document/@form" /> </form> <unid> <xsl:value-of select="preceding-sibling::noteinfo[1]/@unid" /> </unid> <doclink> <xsl:value-of select="@document" /> </doclink> </document> </xsl:for-each> </database> </xsl:template> </xsl:stylesheet> Regards, Mukul --- Brian Benson <bbenson@xxxxxxxxxxxx> wrote: > I am very new to xsl and really struggling to get > the results that I want. > > I am trying to convert an xml file that looks like > this > ==================== > <database> > <document form='formname'> > <noteinfo unid='abc'/> > <doclink document='1'/> > <doclink document='2'/> > </document> > </database> > > Into an xml file that looks like this > ===================== > </database> > <document> > <form>formname</form> > <unid>abc</unid> > <doclink>1</doclink> > </document> > > <document> > <form>formname</form> > <unid>abc</unid> > <doclink>2</doclink> > </document> > </database> > > > The xslt that I have so far works well, except for > the following: > 1) If there is more than one doclink in one > document, they need to be split > into multiple documents so that there is one doclink > per document. The xsl > below puts all doclinks in one document. > 2) The form and unid attributes are output as > attributes and they need to > be converted to elements. > > I have been able to get both of the above to work, > but not at the same > time. Any help is appreciated. > > The xslt that I have so far looks like this: > ===================== > <xsl:template match="/"> > <database> > <xsl:apply-templates/> > </database> > </xsl:template> > > <xsl:template match="dxl:document"> > <document> > <xsl:copy-of select="@form | > dxl:noteinfo/@unid > |.//dxl:doclink"/> > </document> > > <xsl:apply-templates/> > </xsl:template> > > > <!-- remove all other text and attributes --> > <xsl:template match ="text()|@*"></xsl:template> > > <!-- remove all documents with no doc links --> > <xsl:template match > ="dxl:document[not(.//dxl:doclink)]"></xsl:template> > > > > > > XSL-List info and archive: > http://www.mulberrytech.com/xsl/xsl-list > __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] splitting multiple occurrence, Brian Benson | Thread | Re: [xsl] splitting multiple occurr, Brian Benson |
RE: [xsl] Newbie: Embedding styles , Passin, Tom | Date | RE: [xsl] splitting multiple occurr, Passin, Tom |
Month |