我有一个问题,我需要从 xml 生成 html,并且我可以有多个标签相互嵌套。我怎样才能通过递归传递它们?
这是来自 xml 的示例:
<rows>
<row>
<cell>1</cell>
<cell>2</cell>
<cell>1</cell>
<cell>2</cell>
<row>
<cell>3</cell>
<cell>4</cell>
<row>
<cell>5</cell>
<cell>6</cell>
<cell>6</cell>
</row>
</row>
</row>
</rows>
我的 xslt 是:
<table>
<th>1</th><th>2</th>3<th>4</th><th>5</th>
<xsl:for-each select="rows/row">
<tr>
<xsl:for-each select="cell">
<td>
<xsl:value-of select="."/>
</td>
</xsl:for-each>
</tr>
<xsl:for-each select="row">
<tr>
<xsl:for-each select="cell">
<td>
<xsl:value-of select="."/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
所以我现在的问题是如何显示每行中的所有属性?
编辑:从 xslt 生成的 html
<html><body>
<table>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<tr>
<td>1</td>
<td>2</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
</body></html>
第二次编辑:
xslt:
<xsl:template match="cell">
<td style="overflow:hidden;border:1px solid black;">
<div style="width:100px;height:20px;margin-bottom: 10px;margin-top: 10px;">
<xsl:variable name="id1" select="row/@id"/>
<xsl:if test="starts-with(id1, 'Dir')">
<xsl:value-of select="cell/@image"/>
</xsl:if>
<xsl:value-of select="."/>
</div>
</td>
</xsl:template>
xml:
<row id="Dir_44630">
<cell>Text</cell>
<cell>1</cell>
<cell>1.00</cell>
<cell>3</cell>
<cell 4</cell>
<cell>5</cell>
<cell>6</cell>
<cell>7</cell>
</row>