How to use the context () method to place data into a table (XML)

Source: Internet
Author: User
Author: belltree

<singers>
<singer>celine dion</singer>
<singer>britney spears</singer>
<singer>Enya</singe>
<singer>christina aguilera</singer>
<singer>backstreet boys</singer>
<singer>spice girls</singer>
</singers>
In general, when we take out a set of data, we like to put the data into a table, which facilitates data comparison and reading. But XSL does not provide a mechanism for any
Meaning of the group. So you have to use Xsl:if to combine the context () to do this work. The following example returns a two-column table.

<table border= "1" >
<xsl:for-each select= "Singers/singer" >
<xsl:if expr= "(childnumber (this)% 2) = = 1" >
<TR>
<td><xsl:value-of/></td>
<td><xsl:value-of select= ". /singer[index () $gt $ context ()!index ()][0] "/></td>
</TR>
</xsl:if>
</xsl:for-each>
</TABLE>
If you're going to go back to a three-column example, you'll need to add a new, similar code that only generates a new row for every three elements. From this you can infer a need
How the table for n columns is implemented.

<table border= "1" >
<xsl:for-each select= "Singers/singer" >
<xsl:if expr= "(childnumber (this)% 3) = = 1" >
<TR>
<td><xsl:value-of/></td>
<td><xsl:value-of select= ". /singer[index () $gt $ context ()!index ()][0] "/></td>
<td><xsl:value-of select= ". /singer[index () $gt $ context ()!index ()][1] "/></td>
</TR>
</xsl:if>
</xsl:for-each>
</TABLE>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.