Register  |  Login




Advertisement

Start Your Own Q&A Site

Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.

Question

Status: Open Points: 125 Time: 15:22 - Jan 12, 2009  

rpyerneni

How to to loop thru xml nodes

I have this xml data
<products>
<product year="1996" state="TX" rate="9.12"/>
<product year="1997" state="TX" rate="9.23"/>
<product year="1998" state="TX" rate="9.31"/>
<product year="1999" state="TX" rate="9.45"/>
<product year="2000" state="TX" rate="9.98"/>
<product year="2001" state="TX" rate="10.00"/>
<product year="1996" state="NJ" rate="8.34"/>
<product year="1997" state="NJ" rate="9.14"/>
<product year="1998" state="NJ" rate="9.32"/>
<product year="1999" state="NJ" rate="9.65"/>
<product year="2000" state="NJ" rate="9.75"/>
<product year="2001" state="NJ" rate="9.92"/>
</products>

Aftr reaching 4th year, next years should come in next row. Currently with my code the records are coming in single row per each state like this

  1996 1997 1998 1999 2000 2001
TX  9.12 9.23 9.31 9.45 9.98 10.00

 1996 1997 1998 1999 2000 2001
NJ  9.12 9.23 9.31 9.45 9.98 10.00


But I need the output like this...

  1996 1997 1998 1999
TX  9.12 9.23 9.31 9.45
  2000 2001  
  9.98 10.00  

NJ  1996 1997 1998 1999
  8.34 9.14 9.32 9.65
  2000 2001  
  9.75 9.92  

Here is my code

<xsl:key name="state" match="product" use="@state"/>
<xsl:key name="year" match="year" use="concat(@product, ':', @year)"/>
<xsl:key name="rate" match="rate" use="concat(@product, ':', @year,':',@rate)"/>

<table border="1" width="100%">
<tr>
<xsl:for-each select="products/products[generate-id()=generate-id(key('state',@state)[1]
)]">
<xsl:variable name="statecode" select="@state"/>
<td valign='bottom' width='20%' align='left'>
<xsl:value-of select="@state"/>
  </td>
<td colspan='4'>
<table border='1' width='100%' cellspacing='0' cellpadding='0' >
<tr>
<xsl:for-each select="../product[generate-id()=generate-id(key('ltv',concat(@state, ':', @year,':',@rate))[1])]">
<td valign='bottom' align='center' width='22%'>
<xsl:value-of select="@rate"/>
 </td>
</xsl:for-each>
</tr>
</table>

</td>
</tr>
</xsl:for-each>
</xsl:for-each>
</tr>
</table>

Categories

XSL
Answer Discussion
Tutorials

 

jgivoni

Date:: Jan 14, 2009

Time:: 08:20

It seems you're using a <table> to display the product data, which makes it impossible to break lines after 4 columns.
Instead you can try to use <div>s, float them left and give them a width that will make the line break at the right time.

Hope it works,
Jakob

rpyerneni

Date:: Mar 04, 2009

Time:: 12:03

Thank you very much. My problem was solved.

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Tutorials cannot be submitted until the Answer Discussion is complete.

Submit answers in the Answer Discussion area

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

10279

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4848

5.

PeterNZ

3487

6.

gonzalo

2840

7.

Mason

2770

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es