0

您好我正在尝试根据以下输入的样本返回一个表:

<Table TableLevel="1" TableNumber="1" TableTitle="">
  <TableRow TableRowLevel="1" RowTitle="" TableRowNumber="1" class="Even">
    <TableHeader width="33" class="tableheadercell">
      <Paragraph>Account Name</Paragraph>
    </TableHeader>
    <TableHeader width="10" class="tableheadercell">
      <Paragraph>Type</Paragraph>
    </TableHeader>
    <TableHeader width="57" class="tableheadercell">
      <Paragraph>Additional Information</Paragraph>
    </TableHeader>
  </TableRow>
  <TableRow TableRowLevel="1" RowTitle="" TableRowNumber="2" class="OddLegacy">
    <TableCell>
      <Paragraph>ANONYMOUS LOGON</Paragraph>
    </TableCell>
    <TableCell>
      <Paragraph>Group</Paragraph>
    </TableCell>
    <TableCell>
      <UnorderedList UnorderedListLevel="1" class="compactList" UnorderedListNumber="1">
        <ListItem>comment: ANONYMOUS LOGON</ListItem>
        <ListItem>group-id: 7</ListItem>
      </UnorderedList>
    </TableCell>
  </TableRow>
  <TableRow TableRowLevel="1" RowTitle="" TableRowNumber="3" class="Even">
    <TableCell>
      <Paragraph>Administrators</Paragraph>
    </TableCell>
    <TableCell>
      <Paragraph>Group</Paragraph>
    </TableCell>
    <TableCell>
      <UnorderedList UnorderedListLevel="1" class="compactList" UnorderedListNumber="1">
        <ListItem>group-id: 544</ListItem>
      </UnorderedList>
    </TableCell>
  </TableRow>
</Table>

然后是我的 XSLT:

<xsl:variable name="whiteuserxml">
    <item>ANONYMOUS LOGON</item>
</xsl:variable>
<xsl:for-each select="Table">
    <table>
    <xsl:for-each select="TableRow[not(TableCell/Paragraph = $whiteuserxml/item)]">
        <xsl:choose>
        <xsl:when test="count(TableCell) = 0"/>
        <xsl:otherwise>
            <tr>
            <xsl:for-each select="TableHeader">
                <td><b><xsl:apply-templates select="*"/></b></td>
            </xsl:for-each>
            <xsl:for-each select="TableCell">
                        <td><xsl:apply-templates select="*"/></td>
            </xsl:for-each>
               </tr>
        </xsl:otherwise>
        </xsl:choose>
    </xsl:for-each>
    </table>
</xsl:for-each>

期望的输出:

<table>
    <tr>
        <td>Administrators</td><td>Group</td><td>the other stufflist</td>
    </tr>
</table>

我遇到的问题是,如果表为空,我无法阻止创建表,当我确定它是否包含合法行时,为时已晚,无法重新添加表名

4

1 回答 1

0

您可以在表格级别上移动该选择并检查它是否包含单元格

<xsl:when test="count(TableRow/TableCell) = 0"/>

评论:好的,有了“白名单”条件,仍然在提升条件

<xsl:for-each select="Table[count(TableRow[not(TableCell/Paragraph = $whiteuserxml/item)]/TableCell)=0]">...
</xsl:when>

您将不得不在内部循环中再次过滤。

关键是,您可以使用 xslt/xpath 构建在数据树中向前(或其他方向)的复杂条件。您不限于当前节点和属性

于 2012-05-23T06:08:52.540 回答