Subject: Re: [xsl] How to do an 'existence' test in XSL? From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx> Date: Wed, 22 Dec 2004 09:04:34 -0800 (PST) |
Here is a simple approach you can try.. <?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" indent="yes" /> <xsl:template match="/root"> <root> <xsl:for-each select="gui"> <xsl:if test="not(@type = preceding-sibling::gui/@type)"> <xsl:element name="{@type}" /> </xsl:if> </xsl:for-each> </root> </xsl:template> </xsl:stylesheet> When the above XSL is applied to XML - <?xml version="1.0" encoding="UTF-8"?> <root> <gui type="alertBox"></gui> <gui type="tooltip"></gui> <gui type="help"></gui> <gui type="tooltip"></gui> <gui type="alertBox"></gui> <gui type="tooltip"></gui> <gui type="help"></gui> </root> The o/p recieved is - <?xml version="1.0" encoding="UTF-8"?> <root> <alertBox/> <tooltip/> <help/> </root> Regards, Mukul --- ben@xxxxxxxxxxxxx wrote: > I'm having great difficulty understanding how/if XSL > provides the tool to satisfy the following simple > requirement. > > Lets say I have some simple xml like : > > <gui type="alertBox">...</gui> > <gui type="tooltip">...</gui> > <gui type="help">...</gui> > <gui type="tooltip">...</gui> > <gui type="alertBox">...</gui> > <gui type="tooltip">...</gui> > <gui type="help">...</gui> > > To simplify things... imagine transforming this > document in such a way that we have something like : > > <alertBox/> > <tooltip/> > <help/> > > i.e. I would like the XSL to result in one output > per gui type. > > So there is the problem... how on earth do I process > the xml such that it results in an output per +type+ > rather than for each instance (is that explained > well enough?)... i.e. it's easy to match on the > attributes but each match produces output so I would > get : > > <alertBox/><alertBox/> > <tooltip/><tooltip/><tooltip/> > <help/><help/> > > Can anyone offer advice on the way in which I ought > to approach this problem? > > Kindest regards, > > Ben > > __________________________________ Do you Yahoo!? Yahoo! Mail - Easier than ever with enhanced search. Learn more. http://info.mail.yahoo.com/mail_250
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] How to do an 'existence' , Michael Kay | Thread | Re: [xsl] How to do an 'existence' , Dimtre Novatchev |
RE: [xsl] Microsoft .net and XSLT 2, Pieter Reint Siegers | Date | [xsl] Calculating Sum in XSLT 1.0, Abhijit Junnare |
Month |