XML display table using cc

P

Pradeep

When using CSS to display an XML file as a table, is there a way to
show the element names at the tops of the columns as headers?

For Example :
I have a XML file
<ITEMLIST>
<ITEM>
<NAME> Item1 </ITEM>
<PRICE> 500 </PRICE>
<QTY> 10 </QTY>
</ITEM>
<ITEM>
<NAME> Item2 </ITEM>
<PRICE> 600 </PRICE>
<QTY> 20 </QTY>
</ITEM>
<ITEM>
<NAME> Item3 </ITEM>
<PRICE> 700 </PRICE>
<QTY> 25 </QTY>
</ITEM>
<ITEM>
<NAME> Item4 </ITEM>
<PRICE> 900 </PRICE>
<QTY> 90 </QTY>
</ITEM>
</ITEMLIST>

and the output which I want is
 
J

Joe Kesselman

You can certainly do this using XSLT. (CSS is only good at annotating an
existing document structure; XSLT can completely reorganize the data.)
 
P

Pradeep

You can certainly do this using XSLT. (CSS is only good at annotating an
existing document structure; XSLT can completely reorganize the data.)

Thanks for clarifying.....How can we do through XSLT ....Kindly help
 
C

Christian Rühl

Thanks for clarifying.....How can we do through XSLT ....Kindly help

I think this might help you a little: <http://www.w3schools.com/xsl/
xsl_transformation.asp>

One of the upper points called "Start with a Raw XML Document"
followed by "Create an XSL Style Sheet" shows you how to put XML Data
into a table in HTML format. I'm not quite shure if HTML is what you
want, but if, then you should just modify the table structure a little
and its done.

Hope that helps!
 
P

Pradeep

I think this might help you a little: <http://www.w3schools.com/xsl/
xsl_transformation.asp>

One of the upper points called "Start with a Raw XML Document"
followed by "Create an XSL Style Sheet" shows you how to put XML Data
into a table in HTML format. I'm not quite shure if HTML is what you
want, but if, then you should just modify the table structure a little
and its done.

Hope that helps!

Hi Christian Ruhi,

The http://www.w3schools.com/xsl/xsl_transformation.asp gives info
about generating hard-coded table header. I want the header to be
decided by ITEM child elements (in my example its PRICE, and
QTY).....Is there a way to extract this information and display it in
header
 
C

Christian Rühl

Hi Christian Ruhi,

Thehttp://www.w3schools.com/xsl/xsl_transformation.aspgives info
about generating hard-coded table header. I want the header to be
decided by ITEM child elements (in my example its PRICE, and
QTY).....Is there a way to extract this information and display it in
header

You can use the <for-each> function like shown there:

<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>

But you are right, here is "title" and "artist" hard coded. You can
access node attributes with @attributename. So your's should look like
<td><xsl:value-of select="@QTY"/></td> for example. Otherwise you can
declare variables like $variablename. Here: <xsl:variable
name="quantity" select="@OTY"/> and then feed your table using
<xsl:value-of select="$quantity"/>.
 
J

Johannes Koch

Pradeep said:
I want the header to be
decided by ITEM child elements (in my example its PRICE, and
QTY).....Is there a way to extract this information and display it in
header

Use XPath's name() or local-name() functions.
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top