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

RE: Finding position of a node relative to the root in

Subject: RE: Finding position of a node relative to the root instead of the parent node
From: "Cynthia DeLaria" <cdelaria@xxxxxxxxx>
Date: Mon, 22 Dec 2003 15:19:26 -0700
xsl find position
Everything returns "1 down from the root" with this... Is there
something missing?

-----Original Message-----
From: cknell@xxxxxxxxxx [mailto:cknell@xxxxxxxxxx] 
Sent: Monday, December 22, 2003 2:33 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  Finding position of a node relative to the root
instead of the parent node


<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent="yes" encoding="UTF-8" />

  <xsl:template match="/">
    <html>
    <body>
    <xsl:apply-templates />
    </body>
    </html>
  </xsl:template>

  <xsl:template match="nr/featured/movie">
    <div><xsl:value-of select="@title" /> is <xsl:value-of
select="count(ancestor::*) -1" /> down from the root.</div>
  </xsl:template>

  <xsl:template match="nr/also_new/movie">
    <div><xsl:value-of select="@title" /> is <xsl:value-of
select="count(ancestor::*) -1" /> down from the root.</div>
  </xsl:template>

</xsl:stylesheet>
-- 
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     Cynthia DeLaria <cdelaria@xxxxxxxxx>
Sent:     Mon, 22 Dec 2003 14:12:27 -0700
To:       <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Cc:       <btusdin@xxxxxxxxxxxxxxxx>
Subject:   Finding position of a node relative to the root instead
of the parent node

Good Day,
 
I have searched the xsl list unsuccessfully for an answer to this
question, although I'm sure something like this has been addressed. I
think I'm just not sure what to search on to find it.
 
I have the following xml snippet:
 
<nr>
    <featured>
        <movie title="Charlie's Angles: Full
Throttle">Description</movie>
        <movie title="28 Days Later">Description</movie>
        <movie title="The Santa Clause 2">Description</movie>
    </featured>
    <also_new>
        <movie title="Northfork" />
        <movie title="Rudy: The Rudy Giuliani Story" />
        <movie title="Russian Ark" />
    </also_new>
</nr>
 
Basically, in the fully-flushed out version of the XML, the <featured>
movies have images and full descriptions, while the <also_new> movies
have only a title and rating. What I need to do is find a way to find
the position of each <movie> node relative to the root, as I need to
create a "print the new releases" page that lists all new releases in
two columns. This is what I tried, but it gives me the position based on
the parent (i.e. <also_new> or <featured>) not relative to the root.
 
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="ISO-8859-1" /> <xsl:template
match="/nr"> <html> <head> <title>New Releases E-Newsletter</title>
<head> <body bgcolor="#ffffff" text="#000000" link="#023f7e"
alink="#ff0000" vlink="#023f7e"> Just print out this list.<br />
    <table width="100%">
    <xsl:variable name="thisMany"><xsl:value-of
select="(count(//*[name()='movie']) div 2)" /></xsl:variable>
     <tr>
      <td valign="top" width="50%" class="body2">
      <br />
      <xsl:for-each select="//movie[position() < number($thisMany)]">
      <b><i><xsl:value-of select="./@title" /></i></b><br />
      </xsl:for-each>
      <br />
      </td>
      <td valign="top" width="50%" class="body2">
      <br />
      <xsl:for-each select="//*[name()='movie'][position() >
number($thisMany)]">
      <b><i><xsl:value-of select="./@title" /></i></b><br />
      </xsl:for-each>
      <br />
      </td>
     </tr>
    </table>
 </body>
</html>
</xsl:template>
</xsl:stylesheet>
 
Is it possible to get the position relative to the root node? It seems
like this should be very simple, but all of the things I have tried have
not worked to produce the intended outcome.
 
Thank you!

Cynthia
 

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




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


 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.