我有一个 xml 的源代码:
<TableRow TableRowLevel="1" RowTitle="" TableRowNumber="2" class="OddLegacy">
<TableCell>
<Paragraph>10.140.50.50</Paragraph></TableCell>
<TableCell>
<Paragraph>Sun Solaris 8</Paragraph></TableCell>
<TableCell>
<Paragraph>53.1</Paragraph></TableCell>
<TableCell>
<UnorderedList UnorderedListLevel="1" class="compactList" UnorderedListNumber="1">
<ListItem>opusone.dal.veritas.com</ListItem>
<ListItem>OPUSONE</ListItem></UnorderedList></TableCell></TableRow>
<TableRow TableRowLevel="1" RowTitle="" TableRowNumber="3" class="Even">
<TableCell>
<Paragraph>10.140.50.163</Paragraph></TableCell>
<TableCell>
<Paragraph>Sun Solaris 8</Paragraph></TableCell>
<TableCell>
<Paragraph>53.0</Paragraph></TableCell>
<TableCell>
<UnorderedList UnorderedListLevel="1" class="compactList" UnorderedListNumber="1">
<ListItem>dns1.dal.veritas.com</ListItem>
<ListItem>opusone.dal.veritas.com</ListItem></UnorderedList></TableCell></TableRow>
<TableRow TableRowLevel="1" RowTitle="" TableRowNumber="4" class="OddLegacy">
<TableCell>
<Paragraph>10.140.50.82</Paragraph></TableCell>
<TableCell>
<Paragraph>HP-UX 870849686</Paragraph></TableCell>
<TableCell>
<Paragraph>31.4</Paragraph></TableCell>
<TableCell>
<UnorderedList UnorderedListLevel="1" class="compactList" UnorderedListNumber="1">
<ListItem>unknown</ListItem>
<ListItem>testarossa.dal.veritas.com</ListItem></UnorderedList></TableCell></TableRow>
<TableRow TableRowLevel="1" RowTitle="" TableRowNumber="5" class="Even">
<TableCell>
<Paragraph>10.140.50.71</Paragraph></TableCell>
<TableCell>
<Paragraph>Microsoft Windows Server 2008 R2, Enterprise Edition</Paragraph></TableCell>
<TableCell>
<Paragraph>30.5</Paragraph></TableCell>
<TableCell>
<UnorderedList UnorderedListLevel="1" class="compactList" UnorderedListNumber="1">
<ListItem>EVSERV1.evexample.local</ListItem>
<ListItem>EVSERV1</ListItem></UnorderedList></TableCell></TableRow>
如果操作系统(Microsoft Windows Server 2008 R2,企业版)是唯一的,我需要为源中的每一行输出一个表行。到目前为止,我有:
<xsl:for-each select="Table/TableRow[TableCell[2]/Paragraph[not(preceding-sibling::TableCell[2]/Paragraph)]]">
<xsl:sort select="TableCell[2]/Paragraph"/>
<xsl:variable name="newosname" select="TableCell[2]/Paragraph"/>
<xsl:variable name="oscount" select="count(parent::Table/TableRow[TableCell/Paragraph = $newosname])"/>
<tr>
<td>
<xsl:value-of select="$newosname"/>
<xsl:value-of select ="TableCell[2]/Paragraph[not(preceding::TableCell[2]/Paragraph)]"/>
</td>
<td>
<xsl:value-of select="$oscount"/>
</td>
</tr>
</xsl:for-each>
请注意,前面的非测试只是我在尝试测试轴'。
预期产出
<tr>
<td>Sun Solaris 8</td>
<td>2</td>
</tr>
<tr>
<td>HP-UX 870849686</td>
<td>1</td>
</tr>
....