Re: attribute list

Subject: Re: attribute list
From: Eric van der Vlist <vdv@xxxxxxxxxxxx>
Date: Mon, 31 Jan 2000 21:35:16 +0100
Hi Paul,

First, just a minor comment... in your example, <CUSTOMER_ID> and co are
not attributes but elements.

The correct sheet to match your example would be :

        <table cellpadding="3" border="2">
<!--     ^^^^^ (note that TABLE is different from table) -->
        <xsl:for-each select="CUSTOMER/*">
<!--                                  ^^^ you need to loop through the
children of
                                          the CUSTOMER
node                          -->
           <TD><xsl:value-of select="name()"/></TD>
<!--                                 ^^^^^^ @name would be an attribute
named "name" -->

When you are looping through "CUSTOMERS" (btw, don't you mean CUSTOMER
instead ?), you are looping through the instances of the "CUSTOMERS"

What you want to do is looping through the chlibren of a customer

To do this, you need instead something like :

<xsl:for-each select="CUSTOMER/*">

(assuming the current node is a parent of CUSTOMERS).

But you should also take care that if you are writing this like this and
if there are several CUSTOMERS nodes, your loop will be repeated for
each node.

I you want to avoid this, you need to specify which of the customers you
want to use for this loop (for instance <xsl:for-each

You should also note that if you want to process several customers with
a loop like this one taking the first one to set up the headers, you may
have problems if the elements can be specified with a different order
for the different nodes...

Hope this helps


Paul Beer wrote:
> I am trying to loop through the child elements of an element using xslt and
> use the elemnt names of the child nodes as column headers for an html table.
> the xml packet looks like this
>       <CUSTOMER_ID>0000000026</CUSTOMER_ID>
>       <COMPANY>Aero Atlanta Fl</COMPANY>
>       <NAME>Aero Atlanta Flying Club</NAME>
>       <STREET>P.O. Box 819</STREET>
>       <POSTCODE>30144</POSTCODE>
>       <CITY>Kennesaw,</CITY>
>       <PHONE></PHONE>
>       <FAX></FAX>
>    </CUSTOMER>
> what i want to do is dynamically display the child elements as headers in an
> html table, like this :
> <table>
> <tr>
> <td>CUSTOMER_ID</td><td>COMPANY</td><td>NAME</td><td>MAILBOX</td><td>STREET<
> /td><td>POSTCODE</td><td>CITY</td><td>PHONE</td><td>FAX</td>
> </tr>
> <table>
> this doesnt work:
>         <TABLE cellpadding="3" border="2">
>         <TR>
>         <xsl:for-each select="CUSTOMERS">
>            <TD><xsl:value-of select="@name"/></TD>
>         </xsl:for-each>
>         </TR>
>         </table>
> I cant figure out how to get at the value of a child element name from
> within a recursive loop .....
> any suggestions ?
> thanks,
> paul
>  XSL-List info and archive:

Eric van der Vlist                                              Dyomedea                

 XSL-List info and archive:

Current Thread