473,804 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML - Xpath - position() in double loop



Hello everyone,

I contact this discussiongroup because I encountered a little
problem with XSL. Let me explain it:

I have following file "position.x ml":

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="position. xsl"?>

<data>
<curve>
<point>alfa</point>
<point>beta</point>
</curve>
<curve>
<point>gamma</point>
<point>delta</point>
</curve>
</data>

I have following file "position.x sl":

<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>

<xsl:template match="/">
<html>
<body>
<xsl:for-each select="data/curve">
Line: <xsl:number value="position ()" format="1"/><br/>
<xsl:for-each select="./point">
Point: <xsl:number value="position ()" format="1"/><br/>
</xsl:for-each>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

When I run the XML in Internet Explorer under Windows XP, I get
following
result:

Line: 1
Point: 1
Point: 2
Line: 2
Point: 1
Point: 2

My question is now, what must be changed to repeat the line-position
for each
point-position to get the result:

Line/Position: 1 1
Line/Position: 1 2
Line/Position: 2 1
Line/Position: 2 2

I can't find a trick to use the line-position into the internal
point-loop.
Is there a solution (or work around) for this ?

Thanks in advance.

Nov 12 '05 #1
3 5694
Read about xsl:variable

Cheers,
Dimitre Novatchev
"akunamatat a" <pa************ @telenet.be> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .


Hello everyone,

I contact this discussiongroup because I encountered a little
problem with XSL. Let me explain it:

I have following file "position.x ml":

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="position. xsl"?>

<data>
<curve>
<point>alfa</point>
<point>beta</point>
</curve>
<curve>
<point>gamma</point>
<point>delta</point>
</curve>
</data>

I have following file "position.x sl":

<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>

<xsl:template match="/">
<html>
<body>
<xsl:for-each select="data/curve">
Line: <xsl:number value="position ()" format="1"/><br/>
<xsl:for-each select="./point">
Point: <xsl:number value="position ()" format="1"/><br/>
</xsl:for-each>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

When I run the XML in Internet Explorer under Windows XP, I get
following
result:

Line: 1
Point: 1
Point: 2
Line: 2
Point: 1
Point: 2

My question is now, what must be changed to repeat the line-position
for each
point-position to get the result:

Line/Position: 1 1
Line/Position: 1 2
Line/Position: 2 1
Line/Position: 2 2

I can't find a trick to use the line-position into the internal
point-loop.
Is there a solution (or work around) for this ?

Thanks in advance.

Nov 12 '05 #2
Hello!

As Dimitre Novatchev said:

Use Variable, like this:

<xsl:for-each select="data/curve">
<xsl:variable name="linePosit ion" select="positio n()" />
<xsl:for-each select="./point">
Line: <xsl:number value="$linePos ition" format="1" />
Position: <xsl:number value="position ()" format="1"/><br/>
</xsl:for-each>
</xsl:for-each>

--
Pascal Schmitt
Nov 12 '05 #3
Ok, it works. Thanks everybody

Nov 12 '05 #4

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

Similar topics

3
5831
by: Kevin | last post by:
I know this has probably been discussed many times before (I found answers when I searched yesterday), but I still can't get it to work... I have an attribute @OID that can contain any characters (including &quot; and &apos;) I have java code using Xerces to select a node based on it's @OID attribute using an XPath like this:
2
14482
by: girish | last post by:
In my XML document, some node attributes data contains both single quot and double quote characters, such as <input msg="Hello "World", What's up"/>. The double quotes are in form of escape sequence in the XML document. am not able to locate such elements using an XPath expression. I trie the following: //*
1
3179
by: Dave | last post by:
Hi, Can you limit the number or specify which nodes are returned using an xPath query and the XmlDocument.SelectNodes() method? Such as return rows 1 to 25. Or do you have to use a foreach loop and select each node and build a new document from that? Thanks, Dave.
10
2289
by: Michael C# | last post by:
OK, here's the deal. I have a small XML file that represents a small database table. I load it into a System.XML.XMLDocument. So far so good. I run an XPath query against it to retrieve all the field names. Everything there works fine. Here's my XML Document: <?xml version="1.0" standalone="yes" ?> <DataSet1 xmlns="http://www.tempuri.org/DataSet1.xsd"> <tblItem>
4
4405
by: sugoi.sama | last post by:
hi, i'm having a hellish adventure with PHP5 i hope someone just can help me out on this... i'm desperate All i want to do, is to get the index of the returned elements, so i can acess them and change them (i'm guessing this is the only way to do this, as i can't change the element on-the-fly in XPath )
9
2156
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they should work. Also the second nav.OuterXml appears to also be wrong to me. Can someone explain to me why this does not work? (This is an example from a program we have where xpath can be entered in two parts so we have to be able
3
6808
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer> </Root> I would like to retreive "\Root\Customer\Name" out of it. Something like:
2
5956
by: linuxadmin | last post by:
Hello everyone! I evaluate XPath expressions using XPathNavigator and need to know for each result, which line number (or et least file position) it has inside the XML file. Any ideas? Thanks in advice!
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9577
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10569
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10325
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10315
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.