472,958 Members | 2,303 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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.xml":

<?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.xsl":

<?xml version="1.0"?>
<xsl:stylesheet 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 5650
Read about xsl:variable

Cheers,
Dimitre Novatchev
"akunamatata" <pa************@telenet.be> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...


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"?>
<?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.xsl":

<?xml version="1.0"?>
<xsl:stylesheet 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="linePosition" select="position()" />
<xsl:for-each select="./point">
Line: <xsl:number value="$linePosition" 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
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...
2
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...
1
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...
10
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...
4
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...
9
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...
3
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>...
2
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? ...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.