[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Sort by page number

Subject: Sort by page number
From: Jostein Austvik Jacobsen <josteinaj@xxxxxxxxx>
Date: Wed, 21 Oct 2009 17:29:04 +0200
 Sort by page number
I've got a stylesheet that merges XML-files specified in the input
document. Its pretty short so I'll just post the whole thing here:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>
	<xsl:variable name="docs" select="/*/doc"/>
	
	<xsl:template match="mergeDocs">
		<xsl:apply-templates select="doc[1]"/>
	</xsl:template>
	
	<xsl:template match="doc">
		<xsl:variable name="path" select="@path"/>
		<xsl:for-each select="document($path)/*">
			<xsl:sort select=".//@page[1]"/>
			<xsl:copy>
				<article>
				<xsl:copy-of select="@* | *"/>
				</article>
				<xsl:for-each select="$docs[position() &gt; 1]">
					<article>
						<xsl:copy-of select="document(@path)/*/*"/>
					</article>
				</xsl:for-each>
			</xsl:copy>
		</xsl:for-each>
	</xsl:template>
	
</xsl:stylesheet>

The input file can look like this:

<mergeDocs>
  <doc path="doc1.xml"/>
  <doc path="doc2.xml"/>
  <doc path="doc3.xml"/>
</mergeDocs>

As you might figure out from the stylesheet, each of these XML-files
contains an article. There are no metadata available about the
ordering of these articles besides that they usually (not all do, so
"usually") contain a pagebreak tag like this one:

<pagebreak page="36"/>

Lets assume that these pagebreaks can occur at any place within the
article. In the stylesheet above I've tried to sort the articles like
this:

<xsl:sort select=".//@page[1]"/>

In my head this XPath expression reads "in the current article -> go
through all of the descendants -> select all of their attributes ->
pick out the page attributes -> pick the first one".

However, when run; nothing is sorted - as if the xsl:sort wasn't there
at all. I suspect that maybe it searches through the entire document
each time so that all articles are sorted as "page 1"? What am I doing
wrong here...

Regards
Jostein

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.