【发布时间】:2014-09-29 17:22:29
【问题描述】:
我有一个 xml 文件,位于 http://pastie.org/9604783
我将以下 xsl 与 Saxon-HE 一起使用,虽然它不会产生错误(因此它应该是正确的语法),但没有一个 xsl:when 语句似乎被评估为 true,因为所有输出标签都被包装在<bodytext></bodytext> 根据xsl:otherwise 声明。
这些xsl:when 语句的预期效果是以下的一些变体
如果a:t 元素有
一个<p.sld>祖先
AND 有一个 <r> 祖先,它有一个紧跟在前面的兄弟元素,它有一个属性:值对 lvl='1'
然后输出包裹在<bulleted></bulleted> 中的a:t 的内容
OTHERWISE 输出包裹在<bodytext></bodytext> 中的a:t 的内容
输出应包含在什么标签中的变化取决于祖先是 <p.sld> 还是 <p.notes> 以及 lvl 属性的值是 1、2 还是 3
这是我的 XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">
<xsl:output method="xml"/>
<xsl:template match="/">
<document>
<xsl:apply-templates select="//a:t"/>
</document>
</xsl:template>
<xsl:template match="//a:t">
<xsl:choose>
<xsl:when test="(count(ancestor::p:sld) > 0) and (count(ancestor::r/preceding-sibling::node[1][@lvl='1'])) > 0">
<bulleted>
<xsl:value-of select="."/>
</bulleted>
</xsl:when>
<xsl:when test="(count(ancestor::p:sld) > 0) and (count(ancestor::r/preceding-sibling::node[1][@lvl='2'])) > 0">
<bulleted2>
<xsl:value-of select="."/>
</bulleted2>
</xsl:when>
<xsl:when test="(count(ancestor::p:notes) > 0) and (count(ancestor::r/preceding-sibling::node[1][@lvl='2'])) > 0">
<bulleted>
<xsl:value-of select="."/>
</bulleted>
</xsl:when>
<xsl:when test="(count(ancestor::p:notes) > 0) and (count(ancestor::r/preceding-sibling::node[1][@lvl='3'])) > 0">
<bulleted2>
<xsl:value-of select="."/>
</bulleted2>
</xsl:when>
<xsl:otherwise>
<bodytext>
<xsl:value-of select="."/>
</bodytext>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
这是所需的 XML 输出:
<?xml version="1.0" encoding="UTF-8"?>
<document xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">
<bodytext>header text</bodytext>
<bodytext>body text </bodytext>
<bodytext>body text </bodytext>
<bodytext>body text </bodytext>
<bulleted>bulleted text</bulleted>
<bulleted>bulleted text</bulleted>
<bulleted>bulleted text</bulleted>
<bulleted2>bulleted2 text</bulleted2>
<bulleted2>bulleted2 text</bulleted2>
<bulleted2>bulleted2 text</bulleted2>
<bulleted2>bulleted2 text</bulleted2>
<bulleted>bulleted text</bulleted>
<bulleted>bulleted text</bulleted>
<bulleted>bulleted text</bulleted>
<bulleted>bulleted text</bulleted>
<bodytext>body text</bodytext>
<bodytext>body text</bodytext>
<bodytext>footer text</bodytext>
<bodytext>10</bodytext>
<bodytext>10</bodytext>
<bodytext>notes header text</bodytext>
<bodytext>notes body text </bodytext>
<bodytext>notes body text </bodytext>
<bodytext>notes table header text</bodytext>
<bodytext>notes table header text</bodytext>
<bodytext>notes table body text</bodytext>
<bodytext>notes table body text</bodytext>
<bodytext>notes table body text</bodytext>
<bodytext>notes table body text</bodytext>
<bodytext>notes table body text</bodytext>
<bodytext>notes table body text</bodytext>
</document>
【问题讨论】:
-
请将您的示例最小化为仅演示问题所必需的部分。
-
那会很有帮助。