XSLT check if there text between different nodes/ limit amount of translated nodes



I want to check if there is text between different nodes.



XML:



<text>
Line1<newLine></newLine>
Line2<newLine></newLine>
Line3<newLine></newLine><newLine></newLine>
Line4<newLine></newLine><newLine></newLine>
Line5<newLine></newLine><newLine></newLine><newLine></newLine>
Line6<newLine></newLine>
Line7<newLine></newLine><newLine></newLine><newLine></newLine><newLine></newLine>
</text>


My current XSLT is the following:



<xsl:template match="newLine">
<br></br>
</xsl:template>


My current output is the following (Ignore the . at the end):



Line1
Line2
Line3

Line4

Line5


Line6
Line7



.


I want to accept the newLine as a tag, and I want it to translate it to br, but I DONT want to do this when there's more than two times <newLine></newLine>. So I want to accept an empty rule, but not more than one. Besides that, I also DONT want to have one or more empty rules at the end of the output. So after Line7, nothing may happen.


Edit:

To make it a little more clear: If there's <newLine></newLine><newLine></newLine><newLine></newLine>, or even more of them, I want to have a maximum of 2 <br/> elements


How do I do this?


No comments:

Post a Comment