I have the following 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>
Expected Output:
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>
Problem: WIth the above xslt(XPath) I am getting the following output:
Welcome
abc.svg
Sample Text
one.svg
Hello World
Life is good
The innermost nested figure elements two.svg and three.svg are not appearing in the output. But the text is coming from any level. I have a dtd file which has defined that within the chapter element there can be figure element any where. But the order of elements is not known. So I am making a check that if it has a figure element, then display it. I want XSL FO output in pdf format. There is something more needed in the XPath expression name(./following-sibling::*) = 'figure'. I am not getting it. Please help me.
Other solutions tried:
<xsl:if test="current()[name() = 'figure']"></xsl:if>
But Only first figure, abc.svg appears. Thank you.