I’m totally having 27 Detail
element like below, In that I want to split and arrange the Code
element value as per the Indicator Plan
value.
<Details>
<Detail>
<Code>001</Code>
<Type>Alt</Type>
<Plan>N</Plan>
</Detail>
<Detail>
<Code>002</Code>
<Type>Alt</Type>
<Plan>N</Plan>
</Detail>
....
....
....
....
<Detail>
<Code>025</Code>
<Type>Alt</Type>
<Plan>Y</Plan>
</Detail>
<Detail>
<Code>026</Code>
<Type>Alt</Type>
<Plan>Y</Plan>
</Detail>
<Detail>
<Code>027</Code>
<Type>Alt</Type>
<Plan>N</Plan>
</Detail>
</Details>
Per page I need only 20 Code or rows to allow, in that I want the Plan='N'
code should come first and Plan='Y'
Code should come next and I have tried the below code
<xsl:template match="Details">
<xsl:param name="Details" as="element()" tunnel="yes"/>
<xsl:call-template name="Table_Left">
<xsl:with-param name="start_row" as="xs:integer">1</xsl:with-param>
<xsl:with-param name="end_row" as="xs:integer">25</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="Table_Left">
<xsl:param name="start_row" as="xs:integer">0</xsl:param>
<xsl:param name="end_row" as="xs:integer">0</xsl:param>
<xsl:param name="Details" as="element()" tunnel="yes"/>
<xsl:variable name="total_rows">
<xsl:value-of select="count($Details//Detail[Type = 'Alt'])"/>
</xsl:variable>
<xsl:variable name="sorted_plans_alt" as="element()">
<sorted_plans>
<xsl:for-each select="$Details//Detail[Type = 'Alt']">
<xsl:sort select=".//Detail[Type = 'Alt']"
order="ascending" data-type="number"/>
<xsl:sequence select="."/>
</xsl:for-each>
</sorted_plans>
</xsl:variable>
<xsl:variable name="plans_subset">
<xsl:sequence
select="
subsequence($sorted_plans_alt//Detail[Type = 'Alt'], $start_row, $end_row)"
/>
</xsl:variable>
<xsl:variable name="preceding_plan" as="element()">
<preceding_plan>
<xsl:choose>
<xsl:when test="$start_row = 1">
<empty/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence
select="subsequence($sorted_plans_alt//Detail[Type = 'Alt'], $start_row - 1, 1)"
/>
</xsl:otherwise>
</xsl:choose>
</preceding_plan>
</xsl:variable>
<xsl:variable name="rows_to_output" as="xs:integer">
<xsl:variable name="number_of_r_plans" as="xs:integer">
<xsl:value-of
select="count($Details//Detail[Type = 'Alt'])"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$number_of_r_plans > 0">
<xsl:value-of select="$end_row - 5"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$end_row"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="left_table" as="element()">
<xsl:for-each select="($plans_subset//Detail[Type = 'Alt'][Plan='N'])[position() <= $rows_to_output]">
<xsl:value-of select="current()/Code"/>
</xsl:for-each>
<xsl:for-each select="($plans_subset//Detail[Type = 'Alt'][Plan='Y'])[position() <= $rows_to_output]">
<xsl:value-of select="current()/Code"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="right_table">
<topic id="topic_1" xml:lang="en-US" outputclass="review-table-left">
<xsl:apply-templates select="$left_table/*" mode="replaceVariables"/>
</topic>
</xsl:variable>
<xsl:sequence select="$right_table"/>
<xsl:choose>
<xsl:when test="$start_row + $rows_to_output <= $total_rows">
<xsl:call-template name="Table_Left">
<xsl:with-param name="start_row" as="xs:integer"
select="$start_row + $rows_to_output"/>
<xsl:with-param name="end_row" as="xs:integer" select="$end_row"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$start_row = 999"/>
</xsl:choose>
</xsl:template>
In the output below I’m getting 22 codes in the first Page (expecting only 20 codes per page even mentioned in the xsl). But I’m getting Plan='Y'
(025 and 026) codes also.
1st page 2nd page
001 021
002 022
... 023
... 024
020 027
025
026
Expected output would be like below, 20 codes in the first page and remaning codes in the 2nd page. I need Plan=N
Code should come first and Plan=Y
Code should follow
1st page 2nd page
001 021
002 022
... 023
... 024
... 027
... 025
... 026
...
020