<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:param name="startrow"/>
	<xsl:param name="rowcount"/>
	<xsl:template match="/">
		<xsl:element name="IDlist">
			<xsl:choose>
				<xsl:when test="$startrow=''">
					<xsl:choose>
						<xsl:when test="$rowcount=''">
							<xsl:attribute name="startrow"><xsl:value-of select="1"/></xsl:attribute>
							<xsl:attribute name="rowcount"><xsl:value-of select="count(//ID)"/></xsl:attribute>
							<xsl:attribute name="totalrow"><xsl:value-of select="count(//ID)"/></xsl:attribute>
							<xsl:for-each select="//ID">
								<xsl:call-template name="put_ID">
									<xsl:with-param name="start" select="position()"/>
								</xsl:call-template>
							</xsl:for-each>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="startrow"><xsl:value-of select="1"/></xsl:attribute>
							<xsl:attribute name="rowcount"><xsl:value-of select="$rowcount"/></xsl:attribute>
							<xsl:attribute name="totalrow"><xsl:value-of select="count(//ID)"/></xsl:attribute>						
							<xsl:for-each select="//ID[not(position() > number($rowcount))]">
								<xsl:call-template name="put_ID">
									<xsl:with-param name="start" select="position()"/>
								</xsl:call-template>
							</xsl:for-each>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise>
					<xsl:choose>
						<xsl:when test="$rowcount=''">
							<xsl:attribute name="startrow"><xsl:value-of select="$startrow"/></xsl:attribute>
							<xsl:attribute name="rowcount"><xsl:value-of select="count(//ID)"/></xsl:attribute>
							<xsl:attribute name="totalrow"><xsl:value-of select="count(//ID)"/></xsl:attribute>
							<xsl:for-each select="//ID[position() >= $startrow]">
								<xsl:call-template name="put_ID">
									<xsl:with-param name="start" select="position()+number($startrow)-1"/>
								</xsl:call-template>
							</xsl:for-each>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="startrow"><xsl:value-of select="$startrow"/></xsl:attribute>
							<xsl:attribute name="rowcount"><xsl:value-of select="$rowcount"/></xsl:attribute>
							<xsl:attribute name="totalrow"><xsl:value-of select="count(//ID)"/></xsl:attribute>
							<xsl:for-each select="//ID[(position() >= number($startrow)) and not(position() >  number(number($startrow)-1+number($rowcount) )  )]">
								<xsl:call-template name="put_ID">
									<xsl:with-param name="start" select="position()+number($startrow)-1"/>
								</xsl:call-template>
							</xsl:for-each>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
			<!-- xsl:choose>
				<xsl:when test="$startrow=''">
					<xsl:choose>
						<xsl:when test="$rowcount=''">
							<xsl:attribute name="startrow"><xsl:value-of select="1"/></xsl:attribute>
							<xsl:attribute name="rowcount"><xsl:value-of select="999999999"/></xsl:attribute>
							<xsl:attribute name="totalrow"><xsl:value-of select="count(//dir:file[contains(@name,'.xml') and contains(@name,'K')])"/></xsl:attribute>
							<xsl:apply-templates select="//dir:file[contains(@name,'.xml') and contains(@name,'K')]">
								<xsl:with-param name="start" select="'0'"/>
							</xsl:apply-templates>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="startrow"><xsl:value-of select="1"/></xsl:attribute>
							<xsl:attribute name="rowcount"><xsl:value-of select="$rowcount"/></xsl:attribute>
							<xsl:attribute name="totalrow"><xsl:value-of select="count(//dir:file[contains(@name,'.xml') and contains(@name,'K')])"/></xsl:attribute>
							<xsl:apply-templates select="//dir:file[contains(@name,'.xml') and contains(@name,'K') and not(position() >number($rowcount))]">
								<xsl:with-param name="start" select="'0'"/>
							</xsl:apply-templates>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise>
					<xsl:choose>
						<xsl:when test="$rowcount=''">
							<xsl:attribute name="startrow"><xsl:value-of select="$startrow"/></xsl:attribute>
							<xsl:attribute name="rowcount"><xsl:value-of select="999999999"/></xsl:attribute>
							<xsl:attribute name="totalrow"><xsl:value-of select="count(//dir:file[contains(@name,'.xml') and contains(@name,'K')])"/></xsl:attribute>
							<xsl:apply-templates select="//dir:file[contains(@name,'.xml') and contains(@name,'K') and position() >= $startrow ]">
								<xsl:with-param name="start" select="number($startrow)-1"/>
							</xsl:apply-templates>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="startrow"><xsl:value-of select="$startrow"/></xsl:attribute>
							<xsl:attribute name="rowcount"><xsl:value-of select="$rowcount"/></xsl:attribute>
							<xsl:attribute name="totalrow"><xsl:value-of select="count(//dir:file[contains(@name,'.xml') and contains(@name,'K')])"/></xsl:attribute>
							<xsl:apply-templates select="//dir:file[contains(@name,'.xml') and contains(@name,'K') and (position() >= number($startrow)) and not(position() >number(  number($rowcount)+number($startrow)-1 ) )  ]">
								<xsl:with-param name="start" select="number($rowcount)+number($startrow)-1"/>
							</xsl:apply-templates>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
			</xsl:apply-templates -->
		</xsl:element>
	</xsl:template>
	<xsl:template name="put_ID">
		<xsl:param name="start"/>
		<xsl:element name="ID">
			<xsl:attribute name="row"><xsl:value-of select="$start"/></xsl:attribute>
			<xsl:value-of select="."/>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>
