Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7177029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:37:40+00:00 2026-05-28T16:37:40+00:00

Using another code example on stackoverflow we’ve got a paginated print report with headers

  • 0

Using another code example on stackoverflow we’ve got a paginated print report with headers and footers (yes, that old chestnut) working nicely, doing something like this (where RESULTS_ROW has got multiple child nodes):

<xsl:variable name="n" select="number(4)"/>

<xsl:template match="RESULTS">
<body>
<div id="page">
  <output>
    <xsl:apply-templates select="RESULTS_ROW"/>
  </output>
</div>      
</body>
</xsl:template>

<xsl:template match="RESULTS_ROW">              
    <p/>
        [HTML FOR PAGE START]
        <br/>
    <xsl:for-each select=". | following-sibling::RESULTS_ROW[position() &lt; $n]">
        <xsl:value-of select="ITEM43"/><!--Lots more goes in here -->
            <br/>
    </xsl:for-each>
    [HTML FOR PAGE END]
        <p/>
</xsl:template>

The problem came with the need to sort RESULTS_ROW on one of its child node values (ITEM43) before the transformation into lumps of 4 elements takes place otherwise the sorting doesn’t take account of all child nodes.

The output is currently something like

[HTML FOR PAGE START]
North
West
North
River
[HTML FOR PAGE END]

[HTML FOR PAGE START]
West
North
River
North
[HTML FOR PAGE END]

Whereas I want the nodes to be completed sorted before they’re split into groups, something like:

[HTML FOR PAGE START]
North
North
North
North
[HTML FOR PAGE END]

[HTML FOR PAGE START]
River    
River    
West
West
[HTML FOR PAGE END]

I’ve tried everything my not very capable XSL brain can think of but all kinds of sorting, using modes to apply multiple templates to the same node, copying, creating variables containing nodal values etc – nothing seems to work.

Any help would be really appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:37:41+00:00Added an answer on May 28, 2026 at 4:37 pm

    EDIT Right, after a bit of determination and checking exactly what following-sibling does I think I’ve got your solution:

    following-sibling will always process from the original document, not the order you may have it currently sorted in. This means that when you print out the next 4 nodes, it is taking the next 4 nodes in the original document and not conforming to the sort order.

    What you need to do is sort the node list before applying your 4 row template (See code sample below).

    This now populates the variable SortedResults with a string containing a new document, sorted as required. By using the node-set() you can then convert this back into XML and then apply a template.

    There is one more problem in your original RESULTS template that affected your results. You were calling apply-templates over every row so were outputting the next four siblings after each row in the document. This can be resolved with the mod operator shown previously to ensure that the results are only output for every fourth row.

    <?xml version="1.0" encoding="iso-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:exslt="http://exslt.org/common" extension-element-prefixes="exslt">
    
    <xsl:variable name="n" select="number(4)"/>
    
    <xsl:template match="RESULTS">
        <xsl:variable name="SortedResults">
            <xsl:apply-templates select="RESULTS_ROW" mode="sort">
                <xsl:sort select="ITEM43"/>
            </xsl:apply-templates>
        </xsl:variable>
    
        <xsl:variable name="SortedResultsNodeSet" select="exslt:node-set($SortedResults)" />
    
        <body>
            <div id="page">
                <output>
                    <xsl:apply-templates select="$SortedResultsNodeSet/RESULTS_ROW[position() mod $n = 1]" />
                </output>
            </div>
        </body>
    </xsl:template>
    
    <xsl:template match="RESULTS_ROW" mode="sort">
        <xsl:copy-of select="current()"/>
    </xsl:template>
    
    <xsl:template match="RESULTS_ROW">
    
        <p/>
        [HTML FOR PAGE START]
        <br/>
        <xsl:for-each select=". | following-sibling::RESULTS_ROW[position() &lt; $n]">
            <xsl:value-of select="ITEM43"/>
            <br/>
        </xsl:for-each>
        [HTML FOR PAGE END]
        <p/>
    
    </xsl:template>
    
    </xsl:stylesheet>
    

    Please note the additional namespace that has been added so that the node-set() extension method could be used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to dragdrop data from listbox into another applications: Dim
I'm currently re-using JUnit 4 tests from another project against my code. I obtain
i'm using DbSimple, but there is some code which i could write into another
I'm trying to parse a string that was generated by an NSDateFormatter using another
I want to overlay one image with another using CSS. An example of this
im using the google charts libaries , just testing the example code in my
How can maintain a SqlConnection (or using another component) open (connected) always during the
I have an EXE file using a DLL file which is using another DLL
Is it possible to replace the standard broken image via CSS or using another
The title attribute didn't shows. If you have a tip using another attribute type,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.