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

Problems using the "following-sibling"-expression in XPATH

Hi,

I'm using a style-sheet where I make use of the
XPATH-"following-sibling"-expression.

The part which makes problems looks similar to the following code:

---------------------------

<xsl:for-each select="headdata/extension/person">
<xsl:choose>
<xsl:when test="(position()) mod 3 = 1">
<tr>
<td>
<!-- Part 1 works -->
<xsl:text disable-output-escaping="yes">more info::</xsl:text>
<xsl:value-of select="funktion"/>

<!-- Part 2 works -->
<xsl:call-template name="handlePerson">
<xsl:with-param name="persondata" select="."/>
</xsl:call-template>
</td>

<td>
<!-- Part 3 works -->
<xsl:text disable-output-escaping="yes">more info:</xsl:text>
<xsl:value-of select="following-sibling::*[1]/funktion"/>

<!-- Part 4 doens'nt work-->
<xsl:call-template name="handlePerson">
<xsl:with-param name="persondata"
select="following-sibling::*[1]"/>
</xsl:call-template>
</td>

(...)
-----------------------------

I'm in the process of selecting a couple of persons and I want to give
the selected person to a sub-template which should do some processing.

I can access subfields (using following-sibling-expression) of the
current node (see Part 1).
I can access the current node and give it as parameter to the template
"handlePerson" and it works(see Part 2).

I can access subfields of the next sibling (see Part 3) and it works.

But I cannot give the next sibling as parameter to the template
"handlePerson" (see Part 4).

When giving the "following-sibling::*[1]" as parameter to the template
"handlePerson" it always processes the current node; the same with all
other following siblings.

Does anybody have an idea what might be wrong?

Thanks in advance

Peter Rohleder
Jul 20 '05 #1
3 11282
Hi Marrow,

you write:

(...)
Perhaps if you post some example XML and describe what you are actually
trying to achieve? It is difficult to see what the problem might be from
just an incomplete fragment of XSLT code.

I suspect you might be wanting to organize things into a table with a fixed
3 coulumns?


yes, thats true!

I solved the problem by replacing following part, which doesn't work:

<!-- Part 4 doens'nt work-->
<xsl:call-template name="handlePerson">
<xsl:with-param name="persondata"
select="following-sibling::*[1]"/>
</xsl:call-template>


(...)

by(new code):
-----------
<xsl:for-each select="following-sibling::*">
<xsl:if test="position() &lt; 3">

<td>
<xsl:call-template name="handlePerson">
<xsl:with-param name="persondata" select="."/> </xsl:call-template>
</td>

</xsl:if>
</xsl:for-each>
-----------

Now it works, but i still have no idea why the code above doesn't work
and the new code works.

Thanks for your response.

Peter Rohleder

Jul 20 '05 #2
Hi Peter,

If you want to arrange something by a given number of fixed columns then
something like...

== XML =================================
<?xml version="1.0"?>
<headdata>
<extension>
<person>
<name>Aaaa</name>
<funktion>A1</funktion>
</person>
<person>
<name>Bbbb</name>
<funktion>B2</funktion>
</person>
<person>
<name>Cccc</name>
<funktion>C3</funktion>
</person>
<person>
<name>Dddd</name>
<funktion>D4</funktion>
</person>
<person>
<name>Eeee</name>
<funktion>E5</funktion>
</person>
</extension>
</headdata>
== end of XML ==========================

== XSL1 =================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:param name="no-cols" select="3"/>
<xsl:template match="/">
<html>
<body>
<table border="1">
<xsl:apply-templates select="headdata/extension/person[position()
mod $no-cols = 1 or $no-cols = 1]" mode="row-start"/>
</table>
</body>
</html>
</xsl:template>

<xsl:template match="person" mode="row-start">
<tr>
<xsl:apply-templates select=". | following-sibling::person[position()
&lt; $no-cols]"/>
</tr>
</xsl:template>

<xsl:template match="person">
<td>
<xsl:value-of select="name"/>
<br/>
<xsl:text>more info: </xsl:text>
<xsl:value-of select="funktion"/>
</td>
</xsl:template>
</xsl:stylesheet>
== end of XSL1 ==========================

or...

== XSL2 =================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:param name="no-cols" select="3"/>
<xsl:template match="/">
<html>
<body>
<table border="1">
<xsl:for-each select="headdata/extension/person[position() mod
$no-cols = 1 or $no-cols = 1]">
<tr>
<xsl:for-each select=". | following-sibling::person[position()
&lt; $no-cols]">
<td>
<xsl:value-of select="name"/>
<br/>
<xsl:text>more info: </xsl:text>
<xsl:value-of select="funktion"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
== end of XSL2 ==========================

If your XML doesn't look like that then the XSL code might need changing -
but as you haven't posted any example XML that's something you will have to
figure.

The code will also need to be drastically different if you are sorting the
data as it is placed into the table - because axes work on the original
order of the nodes in the input document rather than the sorted node-set.

Cheers
Marrow
"Peter Rohleder" <pe************@epost.de> wrote in message
news:3E************@epost.de...
Hi Marrow,

you write:

(...)
Perhaps if you post some example XML and describe what you are actually
trying to achieve? It is difficult to see what the problem might be from
just an incomplete fragment of XSLT code.

I suspect you might be wanting to organize things into a table with a fixed 3 coulumns?


yes, thats true!

I solved the problem by replacing following part, which doesn't work:

<!-- Part 4 doens'nt work-->
<xsl:call-template name="handlePerson">
<xsl:with-param name="persondata"
select="following-sibling::*[1]"/>
</xsl:call-template>


(...)

by(new code):
-----------
<xsl:for-each select="following-sibling::*">
<xsl:if test="position() &lt; 3">

<td>
<xsl:call-template name="handlePerson">
<xsl:with-param name="persondata" select="."/> </xsl:call-template>
</td>

</xsl:if>
</xsl:for-each>
-----------

Now it works, but i still have no idea why the code above doesn't work
and the new code works.

Thanks for your response.

Peter Rohleder

Jul 20 '05 #3
Peter Rohleder <pe************@epost.de> writes:
I solved the problem by replacing following part, which doesn't work:

<!-- Part 4 doens'nt work-->
<xsl:call-template name="handlePerson">
<xsl:with-param name="persondata"
select="following-sibling::*[1]"/>
</xsl:call-template>


(...)

by(new code):
-----------
<xsl:for-each select="following-sibling::*">
<xsl:if test="position() &lt; 3">

<td>
<xsl:call-template name="handlePerson">
<xsl:with-param name="persondata" select="."/>
</xsl:call-template>
</td>

</xsl:if>
</xsl:for-each>
-----------

Now it works, but i still have no idea why the code above doesn't work
and the new code works.


It's hard to know for sure, since your original example was
fragmentary, but this sure looks like it may be a problem in the
template you are calling. When you pass in a node under the
name 'persondata', you have access in the template to two
conceptually distinct nodes: (1) the $persondata node, and (2)
the current node. If I had to guess, I'd suspect that the
template 'handlePerson' habitually refers to the current node
(i.e. '.') where it should refer to $persondata. Since in some
cases (the calls that work) the two nodes are identical, it
works sometimes, and makes the problem look as if it's a problem
in the call, rather than a problem in the template.

I hope this helps.

-C. M. Sperberg-McQueen
World Wide Web Consortium
Jul 20 '05 #4

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

Similar topics

33
by: Steven Bethard | last post by:
I feel like this has probably been answered before, but I couldn't find something quite like it in the archives. Feel free to point me somewhere if you know where this has already been answered. ...
2
by: Andr? Roberge | last post by:
I want to "import and execute" a python program (input_test.py below) within another program (execute_test.py below) and "watch it" being executed. By watching it, I mean to display the file...
1
by: Newsgroup - Ann | last post by:
Hi gurus, I have two files compiled together. One file has the following global definition: char s = "asdf"; Another file has the following declaration: extern char *s;
13
by: Jalal | last post by:
I am trying to use numeric_limits<double>::min() in an MFC application in Microsoft Visual C++.NET 2003. I am having some difficulties here. The following are the parts of a simple program I wrote...
2
by: Sakharam Phapale | last post by:
Hi All, I am working on a project, where maximum operations carried out on Files and multi-dimensional arrays. Since array data is huge application takes too much memory. My problem is, after...
3
by: bfprog | last post by:
Using IBM iSeries client access OLEDB provider to connect to DB2 on AS/400, but cannot create connection using .NET web app. Using following code: Dim cnTest As New...
14
by: Alf P. Steinbach | last post by:
Not yet perfect, but: http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip To access the table of...
0
by: vaibhavsumant | last post by:
<project name="DBCreate" default="usage" basedir="."> <property name="user" value="db2admin"/> <property name="passwd" value="db2admin"/> <property name="dbprefix" value=""/> <property...
3
by: sangam56 | last post by:
Hello!I am using following sql statement: SELECT Menu.MenuID,Menu.TextUrl FROM Menu WHERE Menu.MenuID= (SELECT Permissions.MenuID FROM Permissions WHERE Permissions.RoleID=(SELECT Roles.RoleID...
1
by: aberry | last post by:
I have text file which contain Unicode data (say inp.txt) I read file using following code:- import codecs infile = codecs.open('C:\\tdata\\inp.txt','r','utf-16',errors='ignore') data =...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.