473,327 Members | 1,967 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,327 software developers and data experts.

Unique attributes and preceding-sibling question

I am having trouble figuring out how to use preceding sibling when I am
already on the node. I have a feeling that you cannot use
preceding-sibling on an attribute, but I can't figure out the syntax.

XML:
<leftcol>
<nav type="extra" location="top">
<boxlink href="#">Link 1</boxlink>
</nav>
<nav type="extra" location="bottom">
<boxlink href="#">Link 1</boxlink>
</nav>
<nav type="right">
<boxlink href="#">Link 1</boxlink>
</nav>
</leftcol>

<xsl:apply-templates select="/leftcol/nav" />

<xsl:if test="@type='extra' and not(@type=preceding-sibling::./@type)">
<!-- More XSL -->
</xsl:if>

The goal is to only output one nav with a type of extra.

Oct 20 '06 #1
4 1736
The problem is your use of ., which is not correct syntax.

You want to look at the preceeding <nav>'s type attribute, so:

<xsl:if test="@type='extra' and not(@type=preceding-sibling::nav/@type)">

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Oct 20 '06 #2

johkar wrote:
XML:
<leftcol>
<nav type="extra" location="top">
<boxlink href="#">Link 1</boxlink>
</nav>
<nav type="extra" location="bottom">
<boxlink href="#">Link 1</boxlink>
</nav>
<nav type="right">
<boxlink href="#">Link 1</boxlink>
</nav>
</leftcol>

<xsl:apply-templates select="/leftcol/nav"/>

<xsl:if test="@type='extra' and
not(@type=preceding-sibling::./@type)">
That's just plain wrong. '.' is a shortcut for the self
axis, so basically you're trying to use two axes at the
same time.
<!-- More XSL -->
</xsl:if>
Generally, if you're asking for help, it's a good idea to
post something that people can stuff into their XSLT
processors right away and see what happens.
The goal is to only output one nav with a type of extra.
So don't use if. *Select* only one nav. Or *match* only one
nav. That's what predicates are for:

<xsl:apply-templates
select="/leftcol/nav[@type='extra'][1]"/>

--
roy axenov

Oct 20 '06 #3

Joseph Kesselman wrote:
You want to look at the preceeding <nav>'s type attribute, so:

<xsl:if test="@type='extra' and not(@type=preceding-sibling::nav/@type)">
Thank you for your help.

Oct 21 '06 #4

roy axenov wrote:
So don't use if. *Select* only one nav. Or *match* only one
nav. That's what predicates are for:

<xsl:apply-templates
select="/leftcol/nav[@type='extra'][1]"/>
Thanks for the great tip.

Oct 21 '06 #5

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

Similar topics

4
by: Victor Engmark | last post by:
When looking for a method to fetch unique elements and counting the number of occurences of each of them, I found quite a lot of gross examples of complex XSL. But after realizing the subtle...
9
by: Rolf Kemper | last post by:
Dear Experts, I got stuck with the following problem and need your help. What I wnat to do is to get a set of distinct nodes. Before the distinct I have selected the multiple occourences...
8
by: Kragen Sitaker | last post by:
ERROR: Cannot insert a duplicate key into unique index pg_class_relname_nsp_index We've been getting this error in our application every once in a while --- typically once an hour to once a day,...
7
by: localhost | last post by:
What is the best and/or fastest way to enumerate attributes of an HTML control? In my page template, I have: <body id="myBody" bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0"...
4
by: p175 | last post by:
What are the advantages / disadvantages of having primary keys in lieu of ordinary indexes ? If there are no foreign relationships defined, is it better to have a two column index allowing reverse...
11
by: garyhoran | last post by:
Hi Guys, I have a collection that contains various attributes (stuff like strings, DateTime and Timespan) . I would like to access the collection in various orders at different points in the...
8
by: sqlservernewbie | last post by:
Hi Everyone, Here is a theoretical, and definition question for you. In databases, we have: Relation
2
by: banderson | last post by:
Hello, I have a data entry form for a table with information about buildings and am having a problem making a combo box do what I want. I would like to make the combo box show a list of unique bldg...
4
by: Mystagogue | last post by:
Given XML like this... <stuff> <thing id="1" result="true"/> <thing id="2" result="true"/> <thing id="3" result="false"/> <thing id="4" result="false"/> <thing id="5" result="error"/>...
0
by: Rajesh Kumar Joshi | last post by:
I have a table with only 1 column as Table : profileTable //-------------- profile XML; //-------------- A sample content of XML file is <sampleprofile name="joe" version="A123">...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.