Pergunta

Hi I'm trying to return a table based on a sample of the following input:

<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>

Then my 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>

Desired output:

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

The problem I'm having is that I can't prevent the table from being created if its going to be empty and by the time I work out whether it contains legitimate rows its too late to add the table name back

Foi útil?

Solução

you can move that choose up at table level and check if it contains cells

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

Review: Ok, with the "white list " conditions, still moving the condition up

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

you will have to filter again in the inner loop.

The point is, you can build complex conditions with xslt/xpath that look forward (or other directions) in the data tree. You are not limited to the current node and attributes

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top