XML: Check if anything exists between two nodes

Posted by sebastian on Stack Overflow See other posts from Stack Overflow or by sebastian
Published on 2010-03-25T20:02:59Z Indexed on 2010/03/25 20:03 UTC
Read the original article Hit count: 388

Filed under:
|
|

Hi there,

I need to find out if anything exists between two nodes. My XML looks like this:

<event value1="1" value2="2" value3="3"
       <info="some info here"/>
          Line 1.</lb>
          Line 2.</lb></lb>
          Line 3.</lb>
          Line 4.</lb>

</event>

My goal is to convert the </lb> nodes to </br> HTML tags using XSLT. There is one additional requirement to fulfill though. In case there is one </lb> directly following another </lb> I want to output only one </br>.

My XSLT looks like this:

 <xsl:template match="lb">
    <xsl:if test="not(preceding-sibling::lb[1])">
       <br/>
    </xsl:if>
 </xsl:template>

The problem with the XSLT above is that it works correctly for line 1 only as the text between both nodes is ignored.

Maybe someone here can help.

© Stack Overflow or respective owner

Related posts about xslt

Related posts about Xml