我的输入XML如下所示:
<thead>
<tr>
<td valign="top"><para><emph type="bold"><emph type="italic">Factor</emph></emph></para></td>
<td valign="top"><para><emph type="bold"><emph type="italic">Important examples</emph></emph></para></td>
<td valign="top"><para><emph type="italic">Content</emph></para></td>
<td valign="top"><para><emph type="bold"><emph type="italic">Page</emph></emph></para></td>
<td valign="top" colspan="2"><para><emph type="bold">Viral infection with</emph> <emph type="bold"><emph type="italic">Myxovirus influenzae</emph></emph></para></td>
</tr>
</thead>
输出应为
<thead>
<tr>
<td valign="top"><para>Factor</para></td>
<td valign="top"><para>Important examples</para></td>
<td valign="top"><para>Content</para></td>
<td valign="top"><para>Page</para></td>
<td valign="top" colspan="2"><para><emph type="bold">Viral infection with</emph> <emph type="bold"><emph type="italic">Myxovirus influenzae</emph></emph></para></td>
</tr>
</thead>
我的XSLT如下所示。
<xsl:template match="emph">
<xsl:choose>
<xsl:when test="ancestor::thead/tr/td/para">
<xsl:value-of select="."></xsl:value-of>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
在XSLT之上运行时,它会删除所有重点,无论是部分强调还是完全强调。但是,我们应该只删除句子中完全强调的节点。如果部分强调句子,那么我们不应该做出任何改变。
答案 0 :(得分:0)
以下XSLT应该可以工作:
(define-struct tree (left right value))
(define example (make-tree
(make-tree empty empty 3)
(make-tree
(make-tree 4 empty 7)
(make-tree empty empty 10) 8)5))
(define app (list 1 2 3 4 6 11 12 13))
(define (insert tree val)
(cond [(empty? tree) (make-tree empty empty val)]
[(= val (tree-value tree)) tree]
[(< val (tree-value tree))
(make-tree (insert (tree-left tree) val) (tree-right tree) (tree-value tree))]
[(> val (tree-value tree))
(make-tree (tree-left tree) (insert (tree-right tree) val) (tree-value tree))]))
(define (insert-list tree lst)
(cond [(empty? lst) tree]
[else (insert-list (insert tree (first lst)) (rest lst))]))
> (insert-list example app)
tree-value: expects a tree, given 4
>