我有下面的XML:匹配节点
<xml>
<start>
<p>Welcome</p>
<figure>
<graphic name="abc.svg"></graphic>
</figure>
<chapter>
<p>Sample text</p>
<figure>
<graphic name="one.svg"></graphic>
</figure>
<chapter>
<figure>
<graphic name="two.svg"></graphic>
</figure>
<p>Hello World</p>
</chapter>
<chapter>
<p>Life is good</p>
<figure>
<graphic name="three.svg"></graphic>
</figure>
</chapter>
</chapter>
</start>
</xml>
预期输出:
Welcome
abc.svg
Sample Text
one.svg
two.svg
Hello World
Life is good
three.svg
XSLT:
<?xml>
<xsl:apply-templates select="$context[name() = 'CHAPTER']" mode="chapter" />
<xsl:template match="node()" mode="chapter">
<xsl:for-each select="node()">
<fo:block margin-left="1mm">
<xsl:if test="name(./following-sibling::*) = 'figure'">
<xsl:apply-templates select="current()[name() = 'FIGURE']" mode="figure"
/>
</xsl:if>
<xsl:value-of select="current()" />
</fo:block>
</xsl:for-each>
</xsl:template>
<xsl:template match="node()[name() = 'figure']" mode="figure">
<xsl:variable name="ImageName">
<xsl:value-of
select="current()/L-GRAPHIC/GRAPHIC/@FILENAME" />
</xsl:variable>
<fo:block>
<fo:external-graphic>
<xsl:attribute name="src"> <xsl:value-of
select="concat('../resources/',
$ImageName)" /> </xsl:attribute>
</fo:external-graphic>
</fo:block>
</xsl:template>
问题: WIt小时以上的XSLT(XPath的)我得到以下输出:
Welcome
abc.svg
Sample Text
one.svg
Hello World
Life is good
的最内层嵌套的附图元件two.svg和three.svg在输出没有出现。但文字来自任何层面。我有一个dtd文件,它已经定义了在章节元素中可以有图元素的任何地方。但是元素的顺序是未知的。 所以我正在检查,如果它有一个数字元素,然后显示它。 我想要PDF格式的XSL FO输出。 在XPath表达式名称(./ following-sibling :: *)='figure'中还有更多需要的东西。我没有得到它。 请帮帮我。
其他解决方案的尝试:
<xsl:if test="current()[name() = 'figure']"></xsl:if>
但只有第一张图,出现abc.svg。 谢谢。
如果你“想要XSL FO输出”,那么请显示实际的XSL-FO代码作为输出 - 任何文本近似都没有多大帮助。另外,您的XSLT样式表不完整。 –