ich ändern möchte spezifischen td zu th in xhtml Datei, wenn das nächste Element Klasse ist 'xxx' und dann diese Elemente löschen (mit Klasse 'xxx') , aber preceding-sibling ist falsch in Vorlage, so muss ich etwas vermissen:XSLT Änderung Elementname - preceding-sibling mißverstanden
<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>
EDIT: Beispieldokument:
<?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>
Was ich will, ist die erste Zeile der Tabelle als th und entfernen Zeile letzte Fehler, falls vorhanden und halten 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>
ich (mit <xsl:template match="//x:tr[following-sibling::x:tr[1]/@class='xxx']/x:td">
, die in XSLT-Dokument jetzt gültig ist) :
<?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>
gibt also keine doctype ist und Bei den Zellen sind Namensräume, die nicht da wären. Ich weiß nicht, wie man die falsche Zeile entfernt (es sollte immer die letzte Zeile sein).
Wie wäre Entsendung eines Eingangs Probe und das Ergebnis, das Sie zusammen mit dem Ergebnis wollen? –