problem @idType = ./@idType

Discussion in 'XML' started by Xh, Mar 27, 2007.

  1. Xh

    Xh Guest

    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
     
    Xh, Mar 27, 2007
    #1
    1. Advertising

  2. Xh

    Xh Guest

    On Mar 27, 1:53 pm, "Xh" <> wrote:
    > 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
     
    Xh, Mar 27, 2007
    #2
    1. Advertising

  3. "Xh" <> writes:

    > <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.
     
    Alain Ketterlin, Mar 27, 2007
    #3
  4. In article <>,
    Xh <> wrote:

    ><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
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
     
    Richard Tobin, Mar 27, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Suurkuusk
    Replies:
    0
    Views:
    4,030
    Andreas Suurkuusk
    Jul 27, 2003
  2. Ted Miller
    Replies:
    0
    Views:
    5,218
    Ted Miller
    Sep 13, 2003
  3. Merek
    Replies:
    0
    Views:
    2,000
    Merek
    Dec 3, 2003
  4. Scott Meddows
    Replies:
    1
    Views:
    421
    John Saunders
    Jun 8, 2004
  5. Mike

    Problem problem problem :( Need Help

    Mike, May 7, 2004, in forum: ASP General
    Replies:
    2
    Views:
    581
    Bullschmidt
    May 11, 2004
Loading...

Share This Page