Hi All,
I want to count the number of passengers individually, which are characterized by their age. For example, age <= 2 years is infant, age <= 12 years is child, else = adult.
I have been given with the date of birth of every passenger. From DOB, I need to calculate the age and then I have to count the passengers in 3 above categories.
Input..
Code:
<ns3:PassengerCounts>
<ns3:PassengerCount BirthDate="1988-04-16"/>
<ns3:PassengerCount BirthDate="1988-04-16"/>
</ns3:PassengerCounts>
In the output, I need to create 3 different variable, which i will then place at the appropriate position.
Code:
<xsl:variable name="adultCount"> ??? </xsl:variable>
<xsl:variable name="childCount"> ??? </xsl:variable>
<xsl:variable name="infantCount"> ??? </xsl:variable>
I have created a following variable, which uses a template to return the passenger age, but I am a bit confused as to how I can count the total number of adults, children and infants from it?
Any help in xslt 1, would be appreciated. Thanks.
Code:
<xsl:variable name="age">
<xsl:call-template name="getAge_template">
<xsl:with-param name="birhtdate" select="@BirthDate"/>
<xsl:with-param name="traveldate" select="//ota:OTA_TT_GroundAvailRQ/ota:Locations[1]/ota:Pickup/@DateTime"/>
</xsl:call-template>
</xsl:variable>
<xsl:template name="getAge_template">
<xsl:param name="birhtdate"/>
<xsl:param name="traveldate"/>
<xsl:param name="pattern">yyyy-MM-dd</xsl:param>
<xsl:param name="age" select="java:text.ParsePosition.new(0)"/>
<xsl:variable name="sdformater" select="java:text.SimpleDateFormat.new($pattern)"/>
<xsl:variable name="bd" select="java:util.Calendar.getInstance()"/>
<xsl:variable name="td" select="java:util.Calendar.getInstance()"/>
<xsl:if test="java:setTimeInMillis($bd, java:getTime(java:parse($sdformater, $birhtdate)))"/>
<xsl:if test="java:setTimeInMillis($td, java:getTime(java:parse($sdformater, $traveldate)))"/>
<xsl:if test="java:setIndex($age, java:get($td, 1) - java:get($bd, 1) )"/>
<xsl:choose>
<xsl:when test="java:get($td, 2) < java:get($bd, 2)">
<xsl:value-of select="java:getIndex($age) -1"/>
</xsl:when>
<xsl:when test=" java:get($td, 2) = java:get($bd, 2) and java:get($td, 5) < java:get($bd, 5)">
<xsl:value-of select="java:getIndex($age) -1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="java:getIndex($age)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>