我想具體的改變TD到日在XHTML文件,如果下一個元素的類是「XXX」,然後刪除該元素(帶班「XXX」)但前同輩是錯誤的模板,所以我必須錯過的東西:XSLT變化元件的名字 - 前同輩誤解
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://www.w3.org/1999/xhtml">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//x:tr[@class='xxx']/preceding-sibling::x:tr/td">
<th>
<xsl:apply-templates select="@* | node()"/>
</th>
</xsl:template>
<xsl:template match="//x:tr[@class='xxx']"/>
</xsl:stylesheet>
編輯: 樣本文檔:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="cs-CZ" xml:lang="cs-CZ">
<head>
<title>test</title>
<meta charset="UTF-8"/>
<link rel="stylesheet" type="text/css" href="xxx.css"/>
</head>
<body>
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr class="xxx">
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr>
<td>error row to remove if present</td>
</tr>
</table>
</body>
</html>
我想是因爲日如果存在刪除最後一個錯誤行並保持HTML5的doctype表的第一行:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="cs-CZ" xml:lang="cs-CZ">
<head>
<title>test</title>
<meta charset="UTF-8"/>
<link rel="stylesheet" type="text/css" href="xxx.css"/>
</head>
<body>
<table>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
</table>
</body>
</html>
我得到(與<xsl:template match="//x:tr[following-sibling::x:tr[1]/@class='xxx']/x:td">
這是目前有效的XSLT文件中) :
<?xml version='1.0' encoding='UTF-8'?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="cs-CZ" xml:lang="cs-CZ">
<head>
<title>test</title>
<meta charset="UTF-8"/>
<link rel="stylesheet" type="text/css" href="xxx.css"/>
</head>
<body>
<table>
<tr>
<th xmlns="" xmlns:x="http://www.w3.org/1999/xhtml">1</th>
<th xmlns="" xmlns:x="http://www.w3.org/1999/xhtml">2</th>
<th xmlns="" xmlns:x="http://www.w3.org/1999/xhtml">3</th>
</tr>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr>
<td>error row to remove if present</td>
</tr>
</table>
</body>
所以沒有DOCTYPE和在這些單元格中,名稱空間不在那裏。我不知道如何刪除錯誤的行(它應該總是最後一行)。
怎麼樣,結果你張貼的輸入採樣和你想要的結果,一起? –