nested if enhancement?

Discussion in 'XML' started by Stephen, Mar 1, 2004.

  1. Stephen

    Stephen Guest

    I want to retrieve the name attribute from each of the entrydata
    elements in the very first viewentry element to create table headings.
    My XSL works by looping through all the elements and checking if it
    is the first element. Then grab the name attribute from each of the
    entrydata elements for the column title. The table must be created
    dynamically since this XSL format will be applied to different XML
    data. I think there is probably a more efficient method than the
    nested if statements. Perhaps a "getFirst()" or something? Would
    someone suggest an improvement?

    My XML:
    <viewentries toplevelentries="46">
    <viewentry position="1">
    <entrydata columnnumber="0" name="Customer Name">
    <text>Pickett, Simona</text>
    </entrydata>
    <entrydata columnnumber="2" name="Phase">
    <text>Port Review</text>
    </entrydata>
    </viewentry>
    </viewentries>

    My XSL:
    <xsl:for-each select="viewentries/viewentry">
    <xsl:if test="position()=1">
    <xsl:for-each select="entrydata">
    <th><xsl:value-of select="@name"/></th>
    </xsl:for-each>
    </xsl:if>
    </xsl:for-each>

    Thank you.
     
    Stephen, Mar 1, 2004
    #1
    1. Advertising

  2. Use:

    /*/viewentry[1]/entrydata/@name

    This selects the nodeset of name attributes that you want to use to create
    table headings.


    Cheers,

    Dimitre Novatchev [XML MVP],
    FXSL developer, XML Insider,

    http://fxsl.sourceforge.net/ -- the home of FXSL
    Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html


    "Stephen" <> wrote in message
    news:...
    > I want to retrieve the name attribute from each of the entrydata
    > elements in the very first viewentry element to create table headings.
    > My XSL works by looping through all the elements and checking if it
    > is the first element. Then grab the name attribute from each of the
    > entrydata elements for the column title. The table must be created
    > dynamically since this XSL format will be applied to different XML
    > data. I think there is probably a more efficient method than the
    > nested if statements. Perhaps a "getFirst()" or something? Would
    > someone suggest an improvement?
    >
    > My XML:
    > <viewentries toplevelentries="46">
    > <viewentry position="1">
    > <entrydata columnnumber="0" name="Customer Name">
    > <text>Pickett, Simona</text>
    > </entrydata>
    > <entrydata columnnumber="2" name="Phase">
    > <text>Port Review</text>
    > </entrydata>
    > </viewentry>
    > </viewentries>
    >
    > My XSL:
    > <xsl:for-each select="viewentries/viewentry">
    > <xsl:if test="position()=1">
    > <xsl:for-each select="entrydata">
    > <th><xsl:value-of select="@name"/></th>
    > </xsl:for-each>
    > </xsl:if>
    > </xsl:for-each>
    >
    > Thank you.
     
    Dimitre Novatchev [MVP XML], Mar 1, 2004
    #2
    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. Marlene

    Re: asp.net calendar enhancement

    Marlene, Jun 25, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    977
    Marlene
    Jun 25, 2003
  2. Fred.

    Re: asp.net calendar enhancement

    Fred., Jun 25, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    3,816
  3. randau
    Replies:
    30
    Views:
    1,441
    Travis Newbury
    May 20, 2005
  4. redguardtoo
    Replies:
    0
    Views:
    330
    redguardtoo
    Jul 26, 2004
  5. redguardtoo
    Replies:
    0
    Views:
    340
    redguardtoo
    Jul 26, 2004
Loading...

Share This Page