problem @idType = ./@idType

X

Xh

Hi all,

I have a problem with generating legend for my data.

I have types and theirs names given like this:
<types>
<type idType="1"><name>Description of type 1</name></type>
<!-- and so on... -->
</types>

And I have my data:

<units>
<unit idUnit="148" idType="1"><!-- stuff here... --></unit>
</units>

I use the for-each loop to iterate through all units, I don't want to
display unit XYZ is of type 1 or 2 or 3...

I wan to use theirs names instead of numbers

I wrote this:
<xsl:for-each select="units/unit">
<xsl:sort select="code"/>
<xsl:value-of select="//types/type[@idType = ./@idType]/name"/>
</xsl:for-each>

but this is wrong since all types have the same <name> value

inside for-each loop current node is ".", but in value-of the same
thing applies and "." becomes the first <type> since all attributes of
types/type are equal to themselves

maybe someone knows how can it be done?

I can not change the names of the attributes I must use them "as
is" (or "as are")

thanks in advance for any help
best regards
Åukasz
 
X

Xh

I wrote this:
<xsl:for-each select="units/unit">
<xsl:sort select="code"/>
<xsl:value-of select="//types/type[@idType = ./@idType]/name"/>
</xsl:for-each>

Hi all,

It has just crossed my mind ;)

<xsl:for-each select="units/medicalUnit">
<xsl:sort select="code"/>
<xsl:variable name="node" select="." />
<xsl:value-of select="//types/type[@idType = $node/@idType]/name"/>
</xsl:for-each>

sorry ;)

best regards
Åukasz
 
A

Alain Ketterlin

Xh said:
<types>
<type idType="1"><name>Description of type 1</name></type>
<!-- and so on... -->
</types>
<units>
<unit idUnit="148" idType="1"><!-- stuff here... --></unit>
</units>
<xsl:for-each select="units/unit">
<xsl:sort select="code"/>
<xsl:value-of select="//types/type[@idType = ./@idType]/name"/>
</xsl:for-each>

Use current() to get the... current node (as apposed to the context
node). So [@idType=current()/@idType] should do what you want.

-- Alain.
 
R

Richard Tobin

Xh said:
<xsl:for-each select="units/medicalUnit">
<xsl:sort select="code"/>
<xsl:variable name="node" select="." />
<xsl:value-of select="//types/type[@idType = $node/@idType]/name"/>
</xsl:for-each>

Yes, variables are the general solution to problems of this type. But
using current() is a simpler solution for the common case where the
variable would be set to ".".

-- Richard
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top