Hi,
I have a sequence of nodes - para>graphic>para. I want to associate the graphic element with its previous sibling "para". However, if there is not a graphic element, I don't need select it.
Here is the input:
Code:
<root>
<para>Data1</para>
<graphic href="img1.gif"/>
<para>Data2</para>
<para>Data3</para>
<para>Data4</para>
<graphic href="img4.gif"/>
<para>Data5</para>
<graphic href="img5.gif"/>
</root>
Stylesheet:
Code:
<xsl:for-each select="root/para">
<xsl:value-of select="."/>
<xsl:text> Image for this para - </xsl:text>
<xsl:value-of select="following-sibling::graphic[1]/@href"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
Current output:
Code:
Data1 Image for this para - img1.gif
Data2 Image for this para - img4.gif
Data3 Image for this para - img4.gif
Data4 Image for this para - img4.gif
Data5 Image for this para - img5.gif
Desired output:
Code:
Data1 Image for this para - img1.gif
Data4 Image for this para - img4.gif
Data5 Image for this para - img5.gif
Thanks for the help.