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

Re: position()

Subject: Re: position()
From: "Steve Muench" <smuench@xxxxxxxxxxxxx>
Date: Fri, 30 Jun 2000 08:03:11 -0700
oracle xml position function
| OUT:
| 2AAA
| 4BBB

This is likely due to how the built-in templates are
interacting with your <xsl:template match="item"/>

Given your example document:

<itemlist>
  <item>
    <name>AAA</name>
  </item>
  <item>
    <name>BBB</name>
  </item>
</itemlist>

If you *just* use the stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="item">
    <xsl:value-of select="position()"/>
    <xsl:value-of select="name"/>
    <p/>
  </xsl:template>
</xsl:stylesheet>

Then before the XSLT processor instantiates your "item" template,
it's gone the the following basic steps:

 (1) Process the root node and find a matching template
 (2) No specific template matches the root, so built-in
     template provides a fallback and processes the
     children nodes of the root (in your case <itemlist>)
 (3) No specific template matches "itemlist" so built-in
     template provides a fallback and processes the 
     children nodes of the <itemlist> element which are:

      1. -text-node-consisting-of-whitespace-
      2. <item>
      3. -text-node-consisting-of-whitespace-
      4. <item>

So as the processor is processing this list of four child
elements, as it considers each <item> element your
<xsl:template match="item"> matches, your position()
function records the position in the context node list
being processed as numbered above.

Here are a few suggestions:

(1) Make sure you have a root template to avoid
    having the built-in templates process children
    nodes that you don't want processed.
 
    The modification of your example below produces
    the result you were expecting because it specifically
    selects the "itemlist/item" nodes for processing.

    <xsl:stylesheet version="1.0" 
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="/">
        <xsl:apply-templates select="itemlist/item"/>
      </xsl:template>
      <xsl:template match="item">
        <xsl:value-of select="position()"/>
        <xsl:value-of select="name"/>
        <p/>
      </xsl:template>
    </xsl:stylesheet>

(2) If whitespace in general is causing problems you
    can get rid of extraneous whitespace-only text node
    children in your document by using <xsl:strip-space>
    The modification of your example below also 
    produces the results you were expecting by requesting
    that the all-whitespace text nodes be removed from
    the source tree before processing:

    <xsl:stylesheet version="1.0" 
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:strip-space elements="*"/>
      <xsl:template match="item">
        <xsl:value-of select="position()"/>
        <xsl:value-of select="name"/>
        <p/>
      </xsl:template>
    </xsl:stylesheet>

See http://www.w3.org/TR/xslt#built-in-rule for more
info on the built-in templates.

______________________________________________________________
Steve Muench, Lead XML Evangelist & Consulting Product Manager
Business Components for Java & XSQL Servlet Development Teams
Oracle Rep to the W3C XSL Working Group
Author "Building Oracle XML Applications", O'Reilly, Oct 2000


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


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.