Go Back   SitePoint Forums > Forum Index > Program Your Site > XML and Web Services
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Dec 5, 2007, 15:56   #1
bbolte
Do or do not, there is no try
 
bbolte's Avatar
 
Join Date: Nov 2001
Location: The Central Plains
Posts: 3,230
Question XSL Operators >= and <=

i have this in an XSL file:
Code:
<xsl:if test="position() &gt; 1 and position() &lt; 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).
bbolte is offline   Reply With Quote
Old Dec 6, 2007, 04:15   #2
kgun
SitePoint Addict
 
Join Date: Nov 2005
Location: Moss, Norway.
Posts: 280
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">
.......................................

</myelement1>

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'))"/>
<xi:fallback>
Broken link or external server down ...
</xi:fallback>
</xi:include>
</myelement1>


Note:
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.

Last edited by kgun; Dec 6, 2007 at 06:04.
kgun is offline   Reply With Quote
Old Dec 6, 2007, 08:38   #3
bbolte
Do or do not, there is no try
 
bbolte's Avatar
 
Join Date: Nov 2001
Location: The Central Plains
Posts: 3,230
woah! i have some reading to do.

thanks for the replay Kjell...
bbolte is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 14:25.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved