This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Where is the benefit ? (Was : RE: The hard cocktail of sequence and (node-)set ..)


Kevin Jones wrote:
> Having had a quick look through the new specs I am confused at where
> the real benefit is for the XPath 2.0 changes other than a few extra
> functions. It's easy to see the improvements in XSLT 2.0 but the
> rest is just passing me by. Anyone care to try and pinpoint what is
> going to make XPath2.0 better rather than just different?

There are a few things that I think are really useful.

General Steps:

Now you don't have to use xsl:for-each to change to the relevant
document in order to use a key or ID. You can use the key() or id()
function within an path. For example:

  document('icons.xml')/key('icons', current()/@name)

The same goes for other expressions that return nodes from nodes. For
example, you can get all the headings in an HTML document with:

  //(h1 | h2 | h3 | h4 | h5 | h6)

rather than using something like:

  //*[self::h1 or self::h2 or self::h3 or
      self::h4 or self::h5 or self::h6]

as you have to in XPath 1.0.


Range Expressions:

Rather than using recursive template or the Piez Method to iterate a
certain number of times, you can now create sequences of a certain
length to iterate over. For example, insert five br elements with:

  <xsl:for-each select="(1 to 5)">
    <br />
  </xsl:for-each>


Node Identity Comparisons:

No more generate-id() = generate-id() or count(.|...) = 1
constructions! Now you can do:

  $node1 == $node2

to test whether two nodes are the same node. Of course the main reason
that we had to use these constructions in the first place was the lack
of grouping support, but nevertheless it's a good thing.


Precedes and Follows Comparisons:

Now you can tell whether one node precedes another within a document
using a simple syntax:

  $node1 << $node2

I can't bring an example to mind right now, but I'm sure there have
been times when I've needed to do that (again, during grouping, I
think).


If Expressions:

Much as I object to keywords, being able to use if/then/else within a
select attribute rather than having an xsl:choose inside a variable,
or using a hideous construction involving concat(), substring() and 1
div 0 is a real godsend :)  For example:

  if (contains($string, $delimiter))
  then substring-before($string, $delimiter)
  otherwise $string


And of course there are the functions:

  - upper-case() and lower-case()
  - match() and replace() (for all they're currently underspecified)
  - min() and max()

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]