XSLT problem

G

Gendag

Hi all,
I have a simple xml file:

<imgs>
<img name="1"/>
<img name="2"/>
<img name="3"/>
<img name="4"/>
</imgs>

And i have the following (simplified) XSLT:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/imgs>
<for-each select="img">
<for-each select="../img">
<xsl:choose>
<xsl:when test="???">
<span style="color: red;">
<xsl:value-of select="@name"/>
</span>
</xsl:when>

<xsl:eek:therwise>
<xsl:value-of select="@name"/>
</xsl:eek:therwise>
</xsl:choose>
</for-each>
</for-each>
</xsl:template>

</xsl:stylesheet>

What I want to do is: for each IMG, print _all_ the IMG and if the IMG
in the second for-each is equal to the IMG in the first for-each, color
it of red. But how can I say with XPath "if the IMG name in equal to the
name of the IMG in the outer for-each"? I remember that there is the
possibility to express it with XPath, but i don't remember how.

Thx!

Gendag
 
J

Joris Gillis

Hi,
Tempore 21:28:13 said:
What I want to do is: for each IMG, print _all_ the IMG and if the IMG
in the second for-each is equal to the IMG in the first for-each, color
it of red. But how can I say with XPath "if the IMG name in equal to the
name of the IMG in the outer for-each"? I remember that there is the
possibility to express it with XPath

There is no such Xpath solution.
You'll have to use at least one variable.
You can use 'current()' to select to context node within Xpath predicates, but there's no way to recall the context node of an outer loop.

regards,
 
T

toudidel

don't use <xsl:for-each> - it's terrible construction (instead of externl
xml document's "looping" with document() function). Instead of it you should
use <xsl:apply-templates match="img"> and <xsl:template match="img">... to
do it
 
G

Gendag

Joris said:
There is no such Xpath solution.
You'll have to use at least one variable.
You can use 'current()' to select to context node within Xpath
predicates, but there's no way to recall the context node of an outer loop.

Thx for the advice, I think I use a variable to solve the problem.
The function of which i didn't remember the name was 'current()', but as
you say, it woks only insiede an Xpath. Thx to rember me the nome of it :)

Gendag
 
G

Gendag

toudidel said:
don't use <xsl:for-each> - it's terrible construction (instead of externl
xml document's "looping" with document() function). Instead of it you should
use <xsl:apply-templates match="img"> and <xsl:template match="img">... to
do it

Thx of the advice.
I know that a recursive style is better of the iterative one, but I used
the 'for-each' beacuse the stylesheet is very simple and i wrote it
quickly :)

Gendag
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,105
Latest member
sheetaldubay7750ync
Top