fistofzen 0 Newbie Poster

I have this XML:

<p>
<span>Foo</span>
<br/>
</p>

<p>
<span>Foo</span>
<br/>
<span>Foo</span>
<span>Foo</span>
<br/>
</p>

<p>
<span>Foo</span>
<span>Foo</span>
<br/>
<span>Foo</span>
<span>Foo</span>
<span>Foo</span>
<br/>
</p>

I would like to be able to select the <br/> tag first and then loop through the spans above them. The reason for this is to get rid of the <br/> tags and replace with <p></p> tags as below:


<p>
<span>Foo</span>
</p>

<p>
<span>Foo</span>
</p>

<p>
<span>Foo</span>
<span>Foo</span>
</p>

<p>
<span>Foo</span>
<span>Foo</span>
</p>

<p>
<span>Foo</span>
<span>Foo</span>
<span>Foo</span>
</p>

This is the sort of xslt I came up with:

<xsl:template match="br">
<p>
<xsl:for-each select="preceding-sibling::span">
<span>
<xsl:value-of select="." />
</span>
</xsl:for-each>
</p>
</xsl:template>


I know it's wrong as it will pick up all the spans within the P tag not just the ones before the previous br tag. Any suggestions truely appreciated
many thanks in advance