我有一个XML文件,该文件是在http://pastie.org/9604783为什么这些xsl:当测试总是被评估为false?
我使用与撒克逊-HE下面的XSL,虽然它不会产生错误(所以它应该是正确的语法)没有任何的xsl:when语句似乎应评估为真,因为所有输出标签都按xsl:otherwise
声明打包在<bodytext></bodytext>
中。
这些xsl:when
语句的预期效果是下列
一些变化IF a:t
元件具有 一个<p.sld>
祖先 并且具有<r>
祖先具有其具有的属性的紧接在前的同级元素:值对lvl='1'
THEN输出的该a:t
的内容包在<bulleted></bulleted>
以其他方式输出该a:t
包裹的内容物在<bodytext></bodytext>
什么标签输出应该被包裹在变化取决于是否祖先是<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>
请将您的示例最小化为仅显示问题的必要条件。 – 2014-09-29 17:29:20
这将有所帮助。 – 2014-09-29 17:36:44