Mukul
To me, your solution is not as simple as it could be.
And I don't think this is really a grouping problem. As the op said this is
an 'existence' problem. If any <gui type="alertBox"> element exists then
generate the appropriate output.
Assuming that the list of gui types is fixed then the following would work:
<xsl:template match="/root">
<root>
<xsl:if test=" gui[(_at_)type='alertBox'] ">
<alertBox/>
</xsl:if>
<xsl:if test=" gui[(_at_)type='tooltip'] ">
<tooltip/>
</xsl:if>
<xsl:if test=" gui[(_at_)type='help'] ">
<help/>
</xsl:if>
</root>
</xsl:template>
Regards
George
George James Software
www.georgejames.com
An InterSystems Technology Partner
-----Original Message-----
From: Mukul Gandhi [mailto:mukul_gandhi(_at_)yahoo(_dot_)com]
Sent: 22 December 2004 17:05
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] How to do an 'existence' test in XSL?
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="{(_at_)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(_at_)autonomic(_dot_)net 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
--~------------------------------------------------------------------
XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
__________________________________
Do you Yahoo!?
Yahoo! Mail - Easier than ever with enhanced search. Learn
more. http://info.mail.yahoo.com/mail_250
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.296 / Virus Database: 265.6.4 - Release Date: 22/12/2004
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.296 / Virus Database: 265.6.4 - Release Date: 22/12/2004
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--