473,382 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

position() question

hi,

I have a structure like:

<topic name="xxx">
<subtopic name="subxxx">
<subsubtopic name="subsubxxx">
</subsubtopic>
</subtopic>
</topic>
and so on.

in the <topic> template I do this:

<tr>
<!-- alternating background-colors: tr.one/tr.two -->
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="position() mod 2 = 0">
<xsl:text>one</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>two</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
to set alternating background-colors (which works fine).
But in a template for 'subsubtopic':

<xsl:template match="topic/subtopic/subsubtopic" mode="toc">

I want to find out the position() of the ancestor <topic> element so that
the <tr>'s generated by this template use the same background-color as the
ancestor <topic> template.

this gives an xpath-error:
<xsl:if test="parent::subtopic/parent::topic/position() mod 2 = 0">

So I tried this (this should return an empty node-set if the position of
the <topic> is odd)
<xsl:if test="parent::subtopic/parent::topic[position() mod 2 = 0]">

but it doesn't work. I also tried this:
<xsl:if test="count(parent::subtopic/parent::topic[position() mod 2 = 0])!=0">

but it doesn't work either. can you explain why?
(I could pass a parameter to the subtopic and subsubtopic templates
which indicates background-color but it seems cleaner this way)

thanks,

--
Felix Natter
Jul 20 '05 #1
1 2170
> But in a template for 'subsubtopic':

<xsl:template match="topic/subtopic/subsubtopic" mode="toc">

I want to find out the position() of the ancestor <topic> element so that
the <tr>'s generated by this template use the same background-color as the
ancestor <topic> template.
This is wrong terminology. position() is defined only for the position of
the current node in the current node-list.

position() also depends on how the template was instantiated (the "select"
attribute of xsl:apply-templates) and can vary for different ways to use
xsl:apply-templates.

But in case you *know* that xsl:apply-templates has been issued against all
siblings topic elements, then what you actually need is:

count(../../preceding-sibling::topic) + 1 mod 2

this gives an xpath-error:
<xsl:if test="parent::subtopic/parent::topic/position() mod 2 = 0">
Yes, position() cannot be used in place of a node-test.

So I tried this (this should return an empty node-set if the position of
the <topic> is odd)
<xsl:if test="parent::subtopic/parent::topic[position() mod 2 = 0]">

but it doesn't work.
Yes, in a tree every node has at most one parent, therefore the position of
the parent is always 1.
I also tried this:
<xsl:if test="count(parent::subtopic/parent::topic[position() mod 2 = 0])!=0">
but it doesn't work either. can you explain why?


The same as above.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Boniface Frederic | last post by:
Hello, I have frame displaying the last posted messages. I set <meta http-equiv="refresh" content="5"/> to automatically refresh the frame every 5s My problem is; if I scroll the frame to see...
3
by: Matthias Lohrer | last post by:
Hi, my XML-Document hat this structure <book> <section> <para /> <para /> </section> <section> <para />
3
by: akunamatata | last post by:
Hello everyone, I contact this discussiongroup because I encountered a little problem with XSL. Let me explain it: I have following file "position.xml": <?xml version="1.0"?>...
1
by: krzys | last post by:
here is the following situation : I have a dataset with two tables this.daCustomers.Fill(dsData1, "Customers"); this.daOrders.Fill(dsData1, "Orders"); as You see there are tables from...
3
by: Kevin Gorski | last post by:
This question has been asked before, but there have been no definitive answers that I was able to find. Can the viewstate hidden input field be moved to a less prominent page location? On an...
1
by: david | last post by:
I have a question about paging index position. When I setup view position of paging index for DataGrid, I can only select the page index position at bottom or on the top. However, The .NET IDE...
8
by: Jeff | last post by:
Ok gang, I am going to try and explain my question. I have a page where a person's position is listed. This is what I am using to get that position. I first sort by the round field in the DB,...
6
by: Gérard Talbot | last post by:
Hello fellow stylers, When trying this page http://www.gtalbot.org/BrowserBugsSection/PercentualRelativePositioning.html I get different rendered layouts with IE 6, IE 7 beta 2, Firefox...
5
by: sheldonlg | last post by:
BootNic wrote: Thanks. That worked on all three browsers. Now I have a problem putting it into my real app. First, I put the javascript into a separate file. I also put the css stuff...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.