【发布时间】:2011-12-21 07:04:23
【问题描述】:
这是我的 XML 文档(小 sn-p)。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p> <!-- Current Node -->
<w:r>
<w:t>
This is the
</w:t>
</w:r>
<w:r>
<w:pict>
<w:p>
<w:r>
<w:t>
I dont need this
</w:t>
</w:r>
</w:p>
</w:pict>
</w:r>
<w:r>
<w:pict>
<w:p>
<w:r>
<w:t>
I dont need this too
</w:t>
</w:r>
</w:p>
</w:pict>
</w:r>
<w:r>
<w:t>
text that i need to retrieve...
</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
在这里,我想检索 <w:r><w:t> 值,并且 <w:r> 中不应包含子 <w:pict>。因此,根据我上面的 XML 文档,我想生成以下输出:
<paragraph>This is the text that i need to retrieve...</paragraph>
这是我的 XSLT sn-p(请告诉我这个 XSLT 需要进行哪些更改才能获得上述格式):
<xsl:choose>
<xsl:when test="self::w:p[//w:r/w:t[not(ancestor::w:pict)]]">
<Paragraph>
<xsl:apply-templates select="./w:t[not(ancestor::w:pict)]" />
</Paragraph>
</xsl:when>
</xsl:choose>
<xsl:template match="w:t">
<xsl:value-of select="." />
</xsl:template>
但它不起作用......
请指导我摆脱这个问题。
【问题讨论】:
-
文本“我不需要这个”包含在
<w:r><w:t>中,而<w:r>不包含子<w:pict>。你能再澄清一下你的要求吗?听起来您需要检查祖先元素,而不是子元素。 -
@TimC : 是的 tim.I 想要获得其祖先不等于
的 值。