2

次のようなソース サンプル ドキュメントがあるとします。

<html>
  <b><i><u>TestBIU</u></i></b>
  <i><b><u>TestIBU</u></b></i>
  <i><u><b>TestIUB</b></u></i>
  <b><u><i>TestBUI</i></u></b>
  <u><i><b>TestUIB</b></i></u>
  <u><b><i>TestUBI</i></b></u>
  <u>TestU</u>
  <i>TestI</i>
  <b>TestB</b>
  <u><b>TestUB</b></u>
</html>

これを生成する XSLT テンプレートが必要です。

<html>
  <b><i>TestBIU</i></b>
  <i><b>TestIBU</b></i>
  <i><b>TestIUB</b></i>
  <b><i>TestBUI</i></b>
  <i><b>TestUIB</b></i>
  <b><i>TestUBI</i></b>
  <u>TestU</u>
  <i>TestI</i>
  <b>TestB</b>
  <b>TestUB</b>
</html>

そのため、下線タグが斜体や太字のタグと組み合わせて使用​​されている場合は、下線タグを削除する必要があります。下線のみの場合は残してください。この特定の問題を解決する方法はありますか?

これが私の試みですが、TestUIB と TestUBI で失敗した場合:

<xsl:template match="/">
    <html>
    <xsl:apply-templates />
    </html>
</xsl:template>
<xsl:template match="b/u">
      <xsl:apply-templates />
</xsl:template>
<xsl:template match="i/u">    
      <xsl:apply-templates />
</xsl:template>
<xsl:template match="u/i">
  <i><xsl:apply-templates /></i>
</xsl:template> 
<xsl:template match="u/b">
    <b><xsl:apply-templates /></b>
</xsl:template>    
<xsl:template match="b | u | i">
    <xsl:copy>
        <xsl:apply-templates select="* | text()"/>
    </xsl:copy>
</xsl:template>
4

2 に答える 2

3

おもう

<xsl:stylesheet 
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="b//u | i//u | u[b] | u[i]">
  <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>

で十分です。

于 2012-11-16T10:46:41.583 に答える