XSL Operators >= and <=

i have this in an XSL file:

<xsl:if test="position() > 1 and position() < 3" >

i really would rather them be >= and <=. any ideas or maybe a better way? this is inside a for-each, i’m subsetting the display (think pagination).

First of all, note that XPath is the foundation for XSLT, so all the functionality and functions from XPath are available within XSLT. In addition XSLT has its own functions and extensions. Since you use the XPath function position(), you should be able to use the XPath operators <=, >= pluss the bolean operator and directly in your test if it is a valid XPath statement. If it is a predicate, it should be enclosed in .

Generally you use this

axis::node test [predicats]

structure while filtering node sets. So you need to know the following concepts to perform tests:

  1. Axes
  2. node test (name test / node type test)
  3. Predicates that filters the node set.

Example filtering from the root node (document node in XPath 2.0).

/*/NodeName1/NodeName2/[position() >= 1 and position() <= 3]

Example of a more advanced filtering based on attributes and an XPath function:

//[local-name()=“MyAttribute”]//[position() >= 1 and position() <= 3]

By combining XPath, XPointer and XInclude, it should also be possible to filter fragments of external documents that can be embedded into your own documents without using any external script or programming language.

Example: You have an external file external.xml with the following structure:

<myelement1 xmlns=xi=“http//www.w3.org/2001/XInclude”>
<myelement2 xml:id=“myID”>


You can then access myelement2 with the myID id in external.xml like this:

<myelement1 xmlns=xi=“http//www.w3.org/2001/XInclude”>
<xi:include href=“external.xml” parse “xml” xpointer=“xpointer(id(‘myID’))”/>
Broken link or external server down …

One advantage with external streaming parsers, is that the memory usage is much lesser than for tree based parsers that operate on the node tree in memory. So if memory usage is critical, that is an argument for using stream based parsers like SAX XML or XMLReader.

woah! i have some reading to do.

thanks for the replay Kjell…