473,396 Members | 1,965 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,396 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 5671
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? ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.