简体   繁体   English

Xpath-我需要帮助为HTML制作表格

[英]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:

<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: 我想要的是一个像这样的表,将xslt转换为带有tr,td和类似内容的HTML:

|_____________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: 您可以像这样用HTML制作表格:

<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. 其中<tr>对于行停留,而<td>对于列停留。

Example from http://www.w3schools.com/xsl/xsl_transformation.asp 来自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>"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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