我無法弄清楚如何在使用xsl:copy-of
時在xhtml輸出文檔中禁止默認屬性shape="rect"
。使用xsl時禁止默認屬性:copy-
示例XML:
<div class="table">
<p class="table-caption"><span class="table-label">Table 7.2</span> Foo<a class="tabfn-ref"
href="#s9781483390086.i825" id="s9781483390086.i808" shape="rect"><sup>a</sup></a> in
Pricing</p>
<img alt="Table 11" class="table-image" src="10.4135_9781483390086-table11.jpg"/>
<table>
<tgroup cols="3">
<colspec align="left" colname="1" colnum="1"/>
<colspec align="left" colname="2" colnum="2"/>
<colspec align="left" colname="3" colnum="3"/>
<thead>
<row rowsep="1">
<entry align="left">
<p/>
</entry>
<entry align="left">
<p>N</p>
</entry>
<entry align="left">
<p>%</p>
</entry>
</row>
</thead>
<tbody>
<row>
<entry>
<p>Foo<a class="tabfn-ref" href="#s9781483390086.i826"
id="s9781483390086.i809" shape="rect"><sup>b</sup></a></p>
<p>1–12</p>
<p>13–24</p>
<p>25–36</p>
<p>37–48</p>
<p>49–60</p>
<p>61–72</p>
<p>73–84</p>
<p>85–96</p>
<p>More than 96</p>
</entry>
</row>
<row>
<entry>
<p>Bar<a class="tabfn-ref" href="#s9781483390086.i827"
id="s9781483390086.i810" shape="rect"><sup>c</sup></a></p>
<p>1–20%</p>
<p>21–40%</p>
<p>41–60%</p>
<p>61–80%</p>
<p>More than 80%</p>
</entry>
</row>
</tbody>
</tgroup>
</table>
<div class="table-notes" id="s9781483390086.i825a">
<p class="table-note" id="s9781483390086.i825b"><span class="label-fn"><a class="tabfn-ref"
href="#s9781483390086.i808" id="s9781483390086.i825" shape="rect"
><sup>a</sup></a></span> Foo</p>
<p class="table-note" id="s9781483390086.i825c"><span class="label-fn"><a class="tabfn-ref"
href="#s9781483390086.i809" id="s9781483390086.i826" shape="rect"
><sup>b</sup></a></span> Bar</p>
<p class="table-note" id="s9781483390086.i825d"><span class="label-fn"><a class="tabfn-ref"
href="#s9781483390086.i810" id="s9781483390086.i827" shape="rect"
><sup>c</sup></a></span> Too</p>
</div>
樣品XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xhtml="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xs xhtml" xmlns="http://www.w3.org/1999/xhtml"
version="2.0">
<xsl:output method="xhtml" indent="yes"/>
<!-- Suppress default shape attribute -->
<xsl:template match="*/@shape"/>
<!-- Identity template -->
<xsl:template match="node()|@*">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template priority="1" match="//div[@class='table']//p[@class='table-caption']"/>
<xsl:template match="table">
<xsl:element name="table">
<xsl:attribute name="hidden" select="'hidden'"/>
<xsl:element name="caption">
<xsl:copy-of select="preceding-sibling::p[@class='table-caption'] | *[not(preceding::a/@shape)]"/>
</xsl:element>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
我需要從輸出抑制shape="rect"
。正如你所看到的,除了使用xsl:copy-of
的那個之外,它從所有錨點的輸出中被抑制。我怎樣才能在行中指定抑制:
<xsl:copy-of select="preceding-sibling::p[@class='table-caption'] | *[not(preceding::a/@shape)]"/>
這顯然不起作用。
輸出:
<div class="table">
<img alt="Table 11" class="table-image" src="10.4135_9781483390086-table11.jpg"/>
<table xmlns="http://www.w3.org/1999/xhtml" hidden="hidden">
<caption>
<p xmlns="" class="table-caption">
<span class="table-label">Table 7.2</span> Foo <a class="tabfn-ref"
href="#s9781483390086.i825" id="s9781483390086.i808" shape="rect">
<sup>a</sup>
</a> in Pricing </p>
</caption>
<tgroup xmlns="" cols="3">
<colspec align="left" colname="1" colnum="1"/>
<colspec align="left" colname="2" colnum="2"/>
<colspec align="left" colname="3" colnum="3"/>
<thead>
<row rowsep="1">
<entry align="left">
<p/>
</entry>
<entry align="left">
<p>N</p>
</entry>
<entry align="left">
<p>%</p>
</entry>
</row>
</thead>
<tbody>
<row>
<entry>
<p>Foo <a class="tabfn-ref" href="#s9781483390086.i826" id="s9781483390086.i809">
<sup>b</sup>
</a>
</p>
<p>1–12</p>
<p>13–24</p>
<p>25–36</p>
<p>37–48</p>
<p>49–60</p>
<p>61–72</p>
<p>73–84</p>
<p>85–96</p>
<p>More than 96</p>
</entry>
</row>
<row>
<entry>
<p>Bar <a class="tabfn-ref" href="#s9781483390086.i827" id="s9781483390086.i810">
<sup>c</sup>
</a>
</p>
<p>1–20%</p>
<p>21–40%</p>
<p>41–60%</p>
<p>61–80%</p>
<p>More than 80%</p>
</entry>
</row>
</tbody>
</tgroup>
</table>
<div class="table-notes" id="s9781483390086.i825a">
<p class="table-note" id="s9781483390086.i825b">
<span class="label-fn">
<a class="tabfn-ref" href="#s9781483390086.i808" id="s9781483390086.i825">
<sup>a</sup>
</a>
</span> Foo </p>
<p class="table-note" id="s9781483390086.i825c">
<span class="label-fn">
<a class="tabfn-ref" href="#s9781483390086.i809" id="s9781483390086.i826">
<sup>b</sup>
</a>
</span> Bar </p>
<p class="table-note" id="s9781483390086.i825d">
<span class="label-fn">
<a class="tabfn-ref" href="#s9781483390086.i810" id="s9781483390086.i827">
<sup>c</sup>
</a>
</span> Too </p>
</div>
</div>
在第一類= 「tabfn-REF」 的形狀屬性保持(由於複製的)。我需要這個被壓制。
請發佈**有效的**代碼(最好最小化到只有必要的),所以我們可以重現這個問題。一般來說,會進行深層複製 - 您無法挑選。 –
2014-11-05 22:03:13