我有个问题 :-)
我想打印一个 xml 并为它写一个 xslt。问题是我想用我的 xml 元素构建一个表,但我必须计算每行是否具有相同数量的列,如果不是,我必须添加一个值元素。
我知道一旦我设置了变量值,我就无法更改变量值,但是我如何比较进程的类别/表行数量呢?(并添加空行)
XML:
<Settings>
...
..
<DashBoard>
<Category NAME="ph" PICNAME="prh">
<Process NAME="pd" URL="" PICNAME="prh_prd" />
<Process NAME="md" URL="" PICNAME="prh_prd" />
<Process NAME="t" URL="" PICNAME="prh_prd" />
</Category>
<Category NAME="cm" PICNAME="cam">
<Process NAME="ps" URL="" PICNAME="cam_pls" />
<Process NAME="ea" URL="" PICNAME="cam_eas" />
</Category>
<Category NAME="sm" PICNAME="sum">
<Process NAME="frm" URL="" PICNAME="sum_frm" />
</Category>
</DashBoard>
</Settings>
XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl=".....">
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="relurl" select="/Settings/Picture/@RELATIVEURL"/>
<xsl:template match="Settings">
<table id="dashframe" >
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="Category">
<xsl:variable name="altname" select="@NAME" />
<xsl:variable name="picname" select="@PICNAME" />
<tr>
<th>
<img alt="{$altname}" src="{$relurl}dash_{$picname}_p_01.png" />
</th>
<xsl:apply-templates/>
</tr>
</xsl:template>
<xsl:template match="Process">
<xsl:variable name="altname" select="@NAME" />
<xsl:variable name="picname" select="@PICNAME" />
<td>
<img alt="{$altname}" src="{$relurl}dash_{$picname}_p_01.png" />
</td>
</xsl:template>
</xsl:stylesheet>
期望的输出:
<table id="dashframe" >
<tr>
<th>titel 1</th>
<td>....</td>
<td>....</td>
<td>....</td>
</tr>
<tr>
<th>titel 2</th>
<td>....</td>
<td>....</td>
<td></td>
</tr>
<tr>
<th>titel 3</th>
<td>....</td>
<td></td>
<td></td>
</tr>
</table>