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

Re: position() problem with // axis + parent numbering probl

Subject: Re: position() problem with // axis + parent numbering problem
From: Warren Hedley <w.hedley@xxxxxxxxxxxxxx>
Date: Tue, 18 Apr 2000 21:50:58 +1200
xsl template getting called twice
Kay Michael wrote:
> 
> Can you tell us *exactly* what you wrote?

Here's the XML, XSL and output (the <temp> elements are just there to add
depth to the tree - making it look a bit more like my real problem).

XML
---
<?xml version="1.0"?>
<!DOCTYPE document>
<document>
  <children>
    <temp>
      <text>P1</text>
      <children>
        <temp>
          <text>P2</text>
          <text>P3</text>
          <text>P4</text>
          <text>P5</text>
        </temp>
      </children>
    </temp>
  </children>
</document>
---

XSL
---
<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:output method="text" />

<xsl:template match="/">

  <xsl:for-each select="//text[1]">
    <xsl:text>First node (</xsl:text>
    <xsl:value-of select="position()" />
    <xsl:text>) = `</xsl:text>
    <xsl:value-of select="." />
    <xsl:text>'
</xsl:text>
  </xsl:for-each>

  <xsl:for-each select="//text[not(position() = 1)]">
    <xsl:text>Text (</xsl:text>
    <xsl:value-of select="position()" />
    <xsl:text>) = `</xsl:text>
    <xsl:value-of select="." />
    <xsl:text>'
</xsl:text>
  </xsl:for-each>

</xsl:template>

</xsl:stylesheet>
---

OUTPUT
---
First node (1) = `P1'
First node (2) = `P2'
Text (1) = `P3'
Text (2) = `P4'
Text (3) = `P5'
---

Note that the first template has been called twice, and a position() call
inside the template returns the correct position in the context list, yet
the result appears to conflict with the predicate [1]. In fact they are
mutually exclusive (whooops), just not what I was expecting.

Any ideas on how I should be phrasing the [not(position() = 1)] predicate?
At the moment I'm getting by checking the result of <xsl:number> inside
the called template.

> I think the <xsl:for-each> here is redundant. The <xsl:number> will give you
> the number of the first ancestor that matches the count pattern.

You're right - I'm sure I tried that! Thanks.

-- 
Warren Hedley
Department of Engineering Science
Auckland University
New Zealand


 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.