Select multiple child nodes

Here should go questions about transforming XML with XSLT and FOP.
eivindan
Posts: 6
Joined: Mon Sep 29, 2008 2:32 pm

Select multiple child nodes

Post by eivindan »

I'm fairly new to XSLT, and struggeling with something that I think should be really simple.

Given the following XML, how can you select the last w:r-element only? (I want to tag the last text with "BoldItalic". )

Code: Select all

<w:p>
<w:r>
<w:rPr>
<w:i/>
</rPr>
<w:t>Some italic text, </w:t>
</w:r>
<w:r>
<w:rPr>
<w:b/>
</rPr>
<w:t>followed by bold text</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:rPr>
<w:i/>
<w:b/>
</rPr>
<w:t>But what about both?</w:t>
</w:r>
</w:p>

Code: Select all


<xsl:template match="w:r/w:rPr/w:i">
<!--do something here-->
</xsl:template>

<xsl:template match="w:r/w:rPr/w:b">
<!--do something here-->
</xsl:template>
ronix
Posts: 12
Joined: Wed Oct 31, 2007 1:25 pm

Re: Select multiple child nodes

Post by ronix »

Code: Select all


<root>
<p>
<r>
<rPr>
<i/>
</rPr>
<t>Some italic text, </t>
</r>
<r>
<rPr>
<b/>
</rPr>
<t>followed by bold text</t>
</r>
</p>
<p>
<r>
<rPr>
<i/>
<b/>
</rPr>
<t>But what about both?</t>
</r>
</p>
</root>

Code: Select all


<xsl:template match="root">
<xsl:apply-templates select="descendant::r[last()]"/>
</xsl:template>
or

Code: Select all


<xsl:template match="root">
<xsl:apply-templates select="descendant::r[not(following-sibling::r)]"/>
</xsl:template>
regards
Post Reply