Hi,
I have a multiple xslt process.
I would like to divide a group, for example the party that start between 20:00:00 until 24:00:00 will call as "Group B" and I would like to record the "number" where is start and end the party_group element can be anywhere, doesn't have to be at the beginning.
Will this be possible to do?

I'm confused how to keep the start and end number. I hope someone can give me some tips. Thanks so much
Here is my input
Code:
<parties>
<events>
<event id="a">
<type>dance party</type>
<title>80s</title>
<start>2009-12-01T00:28:30</start>
</event>
<event id="b">
<type>cocktail party</type>
<title>Flower Garden</title>
<start>2009-12-01T13:09:34</start>
</event>
<event id="c">
<type>cocktail party</type>
<title>Prewedding party</title>
<start>2009-12-01T13:30:34</start>
</event>
<event id="d">
<type>kids party</type>
<title>Fairy Party</title>
<start>2009-12-01T20:00:00</start>
</event>
<event id="e">
<type>kids party</type>
<title>Animals Party</title>
<start>2009-12-01T20:05:00</start>
</event>
</events>
</parties>
I have a two-pass process xslt because I would like to have number to the output look like this as the output
Code:
<mypartiescollection Version="1.1">
<dance_party number="1" id="a">
<title>80s</title>
</dance_party>
<cocktail_party number="2" id="b">
<title>Flower Garden</title>
</cocktail_party>
<cocktail_party number="3" id="c">
<title>Prewedding party</title>
</cocktail_party>
<kids_party number="4" id="d">
<title>Fairy Party</title>
</kids_party>
<kids_party number="5" id="e">
<title>Animals Party</title>
</kids_party>
</mypartiescollection>
Here is my xslt test.xsl
Code:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/" mode="phase1">
<xsl:element name="mypartiescollection">
<xsl:attribute name="Version">1.1</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="event" name="hello">
<xsl:variable name="hours" select="format-number(fn:hours-from-dateTime(xs:dateTime(start)),'00')"/>
<xsl:variable name="minutes" select="format-number(fn:minutes-from-dateTime(xs:dateTime(start)),'00')"/>
<xsl:variable name="seconds" select="format-number(fn:seconds-from-dateTime(xs:dateTime(start)),'00')"/>
<xsl:variable name="eventTime" select="concat($hours,':',$minutes,':',$seconds)"/>
<xsl:if test="xs:time($eventTime) ge xs:time('06:00:00')">
<xsl:element name="party_group">
<xsl:attribute name="name">Group A</xsl:attribute>
<xsl:attribute name="fromNumber"><!-- start number range for example --></xsl:attribute>
<xsl:attribute name="toNumber"><!-- end number range for example 5--></xsl:attribute>
</xsl:element>
</xsl:if>
<xsl:if test="xs:time($eventTime) ge xs:time('20:00:00')">
<xsl:element name="party_group">
<xsl:attribute name="name">Group B</xsl:attribute>
<xsl:attribute name="fromNumber"><!-- start number range for example --></xsl:attribute>
<xsl:attribute name="toNumber"><!-- end number range for example 5--></xsl:attribute>
</xsl:element>
</xsl:if>
<xsl:if test="type='dance party'">
<xsl:element name="dance_party">
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:element name="title">
<xsl:value-of select="title"/>
</xsl:element>
</xsl:element>
</xsl:if>
<xsl:if test="type = 'cocktail party'">
<xsl:element name="cocktail_party">
<xsl:attribute name="id"><xsl:value-of select='@id'></xsl:value-of></xsl:attribute>
<xsl:element name="title">
<xsl:value-of select='title'/>
</xsl:element>
</xsl:element>
</xsl:if>
<xsl:if test="type = 'kids party'">
<xsl:element name="kids_party">
<xsl:attribute name="id"><xsl:value-of select='@id'></xsl:value-of></xsl:attribute>
<xsl:element name="title">
<xsl:value-of select='title'/>
</xsl:element>
</xsl:element>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
and second part xslt
Code:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:import href="test.xslt"/>
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="data">
<xsl:apply-templates select="/" mode="phase1"/>
</xsl:variable>
<xsl:template match="/">
<xsl:apply-templates select="$data" mode="phase2"/>
</xsl:template>
<xsl:template match="mypartiescollection" mode="phase2">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()" mode="phase2"/>
</xsl:copy>
</xsl:template>
<xsl:template match="dance_party|cocktail_party|kids_party" mode="phase2" name="party_collection">
<xsl:copy>
<xsl:attribute name="number">
<xsl:number count="dance_party|cocktail_party|kids_party"/>
</xsl:attribute>
<xsl:copy-of select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
So the output will be like this
Code:
<mypartiescollection Version="1.1">
<party_group name="Group A" fromNumber="1" toNumber="3"/>
<party_group name="Group B" fromNumber="4" toNumber="5"/>
<dance_party number="1" id="a">
<title>80s</title>
</dance_party>
<cocktail_party number="2" id="b">
<title>Flower Garden</title>
</cocktail_party>
<cocktail_party number="3" id="c">
<title>Prewedding party</title>
</cocktail_party>
<kids_party number="4" id="d">
<title>Fairy Party</title>
</kids_party>
<kids_party number="5" id="e">
<title>Animals Party</title>
</kids_party>
</mypartiescollection>