XSLT 1.0を使用して、divベースのXHTMLレイアウトをテーブルベースのレイアウトに変換する必要があります。基本的な変換については、テーブル構造を適切に作成するスタイルシート(以下)があります。
入力XHTMLの複数のクラス属性を解析して、テーブル固有の属性を出力に追加する方法がわかりません。(はい、クラスがコピーされますが、これらを新しいテーブル属性として使用したいと思います)
私のサンプルXHTMLは次のとおりです。
<div class="table align-center">
<div class="tr">
<div class="td"><p>Table Cell 1</p></div>
<div class="td"><p>Table Cell 2</p></div>
</div>
</div>
テーブル構造OKを構築する基本的なXSLは、次のとおりです。
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="div[contains(@class, 'table')]">
<table>
<xsl:copy-of select="attribute::node()"/>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="div[contains(@class, 'tr')]">
<tr>
<xsl:copy-of select="attribute::node()"/>
<xsl:apply-templates/>
</tr>
</xsl:template>
<xsl:template match="div[contains(@class, 'td')]">
<td>
<xsl:copy-of select="attribute::node()"/>
<xsl:apply-templates/>
</td>
</xsl:template>
このスタイルシートは以下を生成します:
<table class="table align-center">
<tr class="tr">
<td class="td"><p>Table Cell 1</p></td>
<td class="td"><p>Table Cell 2</p></td>
</tr>
</table>
私が作りたいのはこれです:
<table class="table align-center" align="center">
<tr class="tr">
<td class="td"><p>Table Cell 1</p></td>
<td class="td"><p>Table Cell 2</p></td>
</tr>
</table>
XSLT 1.0でこれを行うことは可能ですか?2つ以上のクラスを追加し、それらを解析して必要なテーブル属性を追加するのに十分な一般的なソリューションが必要です。
ありがとうございました!