Hi,
The stylesheet would have produced output if your input had been
as described. In your earlier xml, you asked for availability/avail to be
co-related but now it is the availability element itself under the name
'FlightAvailStatus'.
The following stylesheet groups every 2 elements and co-relates with the
first FlightStatusElement. In essence, it treats every 2 AvailFlt elements
as one and prints the first FlightAvailStatus. It is not clear from your
email which flightAvailStatus you want and I chose the first.
When run on the input given by you this styleshsheet produced the following
output:
<?xml version="1.0" encoding="UTF-8"?>
<flightStatus>
Y
Y
N
</flightStatus>
<flight1>
LDN-NYK
BA3246
</flight1>
<flight2>
MAD-CHI
AI1476
</flight2>
<?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="/AirAvail">
<xsl:for-each select="AvailFlt[(position() mod 2) = 0]">
<xsl:call-template name="findflt">
<xsl:with-param name="av1" select="."/>
<xsl:with-param name="av2" select="preceding-sibling::AvailFlt"/>
<xsl:with-param name="pos" select="position()"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="findflt">
<xsl:param name="av1"/>
<xsl:param name="av2"/>
<xsl:param name="pos"/>
<xsl:text>
</xsl:text>
<xsl:for-each select="following-sibling::FlightAvailStatus[(position() mod
2) = 1]">
<flightStatus>
<xsl:value-of select="."/>
</flightStatus>
<flight1>
<xsl:value-of select="$av1"/>
</flight1>
<flight2>
<xsl:value-of select="$av2"/>
</flight2>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Cheers,
Omprakash.V
Ahsan Ali
<doubleletter@ To:
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
gmail.com> cc: (bcc: omprakash.v/Polaris)
Subject: Re: [xsl] Using
xsl:for-each for every 2 elements ?
05/31/2005
12:30 PM
Please respond
to xsl-list
I'm sorry for the confusion but I believe I erred in that example data:
Here's a precise version
<AirAvail>
<AvailFlt>
<name></name>
<flightno></flightno>
</AvailFlt>
<AvailFlt>
<name></name>
<flightno></flightno>
</AvailFlt>
<FlightAvailStatus>
<coach>Y</coach>
<first>Y</first>
<business>N</business>
</FlightAvailStatus>
<FlightAvailStatus>
<coach>Y</coach>
<first>Y</first>
<business>N</business>
</FlightAvailStatus>
</AirAvail>
For clarity's sake, I'll restate the requirement: I want to group
every 2 AvailFlt elements; at the same time, while displaying the data
of each element, I want to display its availability status in the
corresponding FlightAvailStatus element. The only thing that relates
the two elements is their position (or order)....
I tried the below solution (by OmPrakash) but it gives me no output...
Thanks for your time !
Regards,
Ahsan
On 5/31/05, omprakash(_dot_)v(_at_)polaris(_dot_)co(_dot_)in
<omprakash(_dot_)v(_at_)polaris(_dot_)co(_dot_)in> wrote:
Hi,
This is a modified version of the stylesheet to accoodate for
the
fact that you had asked for every other element to be processed.
I am not sure if I got your requirement right and if someone has answered
this question already. This is an independent effort and not based on
anyone else' solution.
<?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="/data">
<xsl:for-each select="availability/avail[(position() mod 2) = 0]">
<xsl:call-template name="findflt">
<xsl:with-param name="av" select="."/>
<xsl:with-param name="pos" select="position()"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="findflt">
<xsl:param name="av"/>
<xsl:param name="pos"/>
<xsl:text>
</xsl:text>
<xsl:for-each select="preceding::flights/flt[(position() mod 2) = 0]">
<xsl:if test="position() = $pos">
<xsl:value-of select="."/>
<xsl:value-of select="$av"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Cheers,
Omprakash.V
This e-Mail may contain proprietary and confidential information and is
sent for the intended recipient(s) only.
If by an addressing or transmission error this mail has been misdirected
to you, you are requested to delete this mail immediately.
You are also hereby notified that any use, any form of reproduction,
dissemination, copying, disclosure, modification,
distribution and/or publication of this e-mail message, contents or its
attachment other than by its intended recipient/s is strictly prohibited.
Visit Us at http://www.polaris.co.in
--~------------------------------------------------------------------
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>
--~--
--~------------------------------------------------------------------
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>
--~--
This e-Mail may contain proprietary and confidential information and is sent
for the intended recipient(s) only.
If by an addressing or transmission error this mail has been misdirected to
you, you are requested to delete this mail immediately.
You are also hereby notified that any use, any form of reproduction,
dissemination, copying, disclosure, modification,
distribution and/or publication of this e-mail message, contents or its
attachment other than by its intended recipient/s is strictly prohibited.
Visit Us at http://www.polaris.co.in
--~------------------------------------------------------------------
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>
--~--