English 中文(简体)
基于儿童价值的建筑表
原标题:Building Table based on child values

Hi Im 试图根据以下输入的样本返回一张表格 :

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

我面临的问题是,如果表格空空,我无法阻止创建表格,而当我确定它是否包含合法行时,我无法阻止它被创建,因为我无法阻止它被创建,而当我确定它是否包含合法行时,我为时太晚,无法在表格名称后面添加

最佳回答

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

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

您必须在内部循环中再次过滤。

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

问题回答

暂无回答




相关问题
When test hanging in an infinite loop

I m tokenising a string with XSLT 1.0 and trying to prevent empty strings from being recognised as tokens. Here s the entire function, based on XSLT Cookbook: <xsl:template name="tokenize"> ...

quick xslt for-each question

Let s say I have an XML document that has this: <keywords> <keyword>test</keyword> <keyword>test2</keyword> <keyword>test3</keyword> <keyword>test4</...

XSLT Transform XML with Namespaces

I m trying to transform some XML into HTML using XSLT. Problem: I can t get it to work. Can someone tell me what I m doing wrong? XML: <ArrayOfBrokerage xmlns:i="http://www.w3.org/2001/...

XSLT output to HTML

In my XSLT file, I have the following: <input type="button" value= <xsl:value-of select="name">> It s an error as it violates XML rule. What I actually want is having a value from an ...

Mangling IDs and References to IDs in XML

I m trying to compose xml elements into each other, and the problem I am having is when there s the same IDs. Basically what I need to do is mangle all the IDs in an xml file, as well as the ...

Sharepoint 2007 Data view Webpart custom parameters

I m sort of new to the custom parameters that can be setup on a DataView Webpart. There are 6 options: - None - Control - Cookie - Form - QueryString - Server Variable I think that None, Cookie and ...

热门标签