By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,836 Members | 2,062 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,836 IT Pros & Developers. It's quick & easy.

XML - Xpath - position() in double loop

P: n/a


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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
Ok, it works. Thanks everybody

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.