简体   繁体   中英

Xpath - I need help making a table for an html

I'm trying to make a table with this:

Input:

<root>
<vendedor>
     <nombre>nombre1</nombre>
     <descrip>descrip1</descrip>
</vendedor>
 <vendedor>
     <nombre>nombre1</nombre>
     <descrip>descrip2</descrip>
</vendedor>
<vendedor>
     <nombre>nombre1</nombre>
     <descrip>descrip3</descrip>
</vendedor>
....
<vendedor>
     <nombre>nombre2</nombre>
     <descrip>descrip1</descrip>
</vendedor>
<vendedor>
     <nombre>nombre2</nombre>
     <descrip>descrip3</descrip>
</vendedor>
....
</root>

xsl:

<xsl:for-each select="//vendedor[not(nombre=preceding-sibling::vendedor/nombre)]/nombre">
<xsl:value-of select="."/>
    <xsl:for-each select="//vendedor[nombre=current()]/descrip">
    <xsl:value-of select="."/>
    </xsl:for-each>
</xsl:for-each> 

What I want is a table like this transforming the xslt into an HTML with tr,td and stuff like this:

|_____________nombre____________|
|descrip|descrip|descrip|descrip|
|descrip|descrip|descrip|descrip|

I have been trying but I don't get what I want so..., Can someone help me?

Expected output:

<table>
<tr>
  <th>nombre</th>
</tr>
<tr>
  <td>descrip</td>
  <td>descrip</td>
  <td>descrip</td>
  <td>descrip</td>
</tr>
<tr>
  <td>descrip</td>
  <td>descrip</td>
  <td>descrip</td>
  <td>descrip</td>
</tr>
<tr>
.....
</tr>
....
<tr>
  <th>nombre</th>
</tr>
<tr>
  <td>descrip</td>
  <td>descrip</td>
  <td>descrip</td>
  <td>descrip</td>
</tr>
.....
</xsl:for-each>
</table>

You can make a table in HTML like this:

<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th>Title</th>
      <th>Artist</th>
    </tr>
    <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>
  </table>
  </body>
  </html>
</xsl:template>

Where <tr> stays for rows and <td> for columns.

Example from http://www.w3schools.com/xsl/xsl_transformation.asp

Table for your example would be:

  "<table border="1">
    <tr bgcolor="#9acd32">
      <th>nombre</th>
    </tr>
    <xsl:for-each select="catalog/cd">
    <tr>
      <td><xsl:value-of select="title"/></td>
      <td><xsl:value-of select="title"/></td>
      <td><xsl:value-of select="title"/></td>
      <td><xsl:value-of select="title"/></td>
      <td><xsl:value-of select="title"/></td>
    </tr>
    </xsl:for-each>
  </table>"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM