请教xlst高手~~
<Table ExpandedColumnCount= "9 " ExpandedRowCount= "9 " DefaultColumnWidth= "84 " DefaultRowHeight= "18 ">
<Row>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
</Row>
<Row>
<Cell StyleID= "1 " DataType= "0 " MergeAcross= "4 " MergeDown= "1 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "2 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String "> 111 </Data>
</Cell>
<Cell StyleID= "2 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String "> 2222 </Data>
</Cell>
<Cell StyleID= "2 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
</Row>
<Row>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
<Cell StyleID= "1 " DataType= "0 " IsMoney= "False ">
<Data xml:space= "preserve " Type= "String " />
</Cell>
</Row>
</table>
以上应该容易理解吧?!
Cell的属性MergeAcross= "4 "表示4个单元格合并,但被合并的单元格在xml中也存在并且没有特殊标记.
我要通过xslt将此xml转换成html,带MergeAcross属性的我可以转换成colspan= "4 ",但后面应该忽略掉3个单元格的循环输出应该怎样做??请高手指点! 3Q !!
[解决办法]
<?xml version= "1.0 " encoding= "utf-8 "?> <!-- DWXMLSource= "1.xml " --> <!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp "  ">
<!ENTITY copy "© ">
<!ENTITY reg "® ">
<!ENTITY trade "™ ">
<!ENTITY mdash "— ">
<!ENTITY ldquo "“ ">
<!ENTITY rdquo "” ">
<!ENTITY pound "£ ">
<!ENTITY yen "¥ ">
<!ENTITY euro "€ ">
]>
<xsl:stylesheet version= "1.0 " xmlns:xsl= "http://www.w3.org/1999/XSL/Transform ">
<xsl:output method= "html " encoding= "utf-8 " doctype-public= "-//W3C//DTD XHTML 1.0 Transitional//EN " doctype-system= "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "/>
<xsl:template match= "/ ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=utf-8 "/>
<title> Untitled Document </title>
</head>
<body>
<table width= "100% " border= "1 " cellspacing= "0 " cellpadding= "0 " align= "center " bordercolor= "red ">
<xsl:for-each select= "Table/Row[position() > 1] ">
<xsl:choose>
<xsl:when test= "Cell/@MergeAcross ">
<xsl:variable name= "MergeAcross "> <xsl:value-of select= "Cell/@MergeAcross "> </xsl:value-of> </xsl:variable>
<xsl:variable name= "CellCount "> <xsl:value-of select= "count(Cell) "> </xsl:value-of> </xsl:variable>
<tr>
<xsl:for-each select= "Cell[(1 < position()) and (position()< (($CellCount)-($MergeAcross)+2))] ">
<td size= "7 ">
<xsl:attribute name= "align "> right </xsl:attribute>
<xsl:attribute name= "colspan "> <xsl:value-of select= "@MergeAcross "/> </xsl:attribute> #
</td>
</xsl:for-each>
</tr>
</xsl:when>
<xsl:otherwise>
<tr>
<xsl:for-each select= "Cell[position() > 1] ">
<td> <xsl:attribute name= "align "> right </xsl:attribute>
<xsl:attribute name= "width "> <xsl:value-of select= "../../@DefaultColumnWidth "/> </xsl:attribute>
# </td>
</xsl:for-each>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
就加个and就可以了
[(1 < position()) and (position()< (($CellCount)-($MergeAcross)+2))
< 就是 <符号
1 <position <总数-合并数