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

Assigning serial numbers

Subject: Assigning serial numbers
From: "Siddhi Thakkar" <siddhi.thakkar@xxxxxxxxxxxxxx>
Date: Tue, 13 Apr 2010 10:44:07 +0530
 Assigning serial numbers
Thanks for the valuable inputs Michael. I will surely keep these in mind.


Date: Sat, 10 Apr 2010 10:30:59 +0100 To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> From: "Michael Kay" <mike@xxxxxxxxxxxx> Subject: RE: Assigning serial numbers Message-ID: <08A6868B7F1D4D8094D70747568B5DFD@Sealion>

<xsl:template match="//a"> <xsl:for-each select="@href"> <xsl:if test="not(for $x in //@id return $x[$x=current()])">

This is very peculiar coding!

(a) Don't write match="//a", write match="a". The meaning is 99% the same
except (i) the precedence of the rule is different, and (ii) the second form
is cheaper because it doesn't have to check that the element is part of a
document tree.

(b) It's odd to do a for-each over a singleton.

(c) The construct (for $x in EXP return $x[PRED]) is equivalent to EXP[PRED]

So you could write

<xsl:template match="a">
 <xsl:if test="not(//@id[. = current()/@href])">

(d) For repeated searches like this it's best to define a key:

<xsl:key name="k" match="*" use="@id"/>


<xsl:template match="a
<xsl:if test="not(key('k', @href))">

<!-- This is where I would like to write the code to assign serial

The simplest way to do this is to only select the <a> elements you want to
include in the table; then position() gives you what you need:

<xsl:key name="k" match="*" use="@id"/>

<xsl:template match="/">
          <xsl:apply-templates select="//a[not(key('k', @href))]">

<xsl:template match="a">
       <xsl:value-of select="position()"/>
       <xsl:value-of select="@href"/>


Michael Kay


Current Thread


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.
First Name
Last Name
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.