Altova Mailing List Archives

Re: [xsl] Trying to select sibling nodes between two nodes

From: "G. Ken Holman" <gkholman@----------------.--->
To: xsl-list@-----.------------.---
Date: 1/8/2010 10:21:00 PM
At 2010-01-08 16:12 -0600, Ylvisaker, Steve wrote:
>I have some unfortunate xml that I am trying to parse:
><label>first text<br/>second<emphasis>bold</emphasis> text<br/>third 
>I need to transform this into:
>  <flowPara>first text</flowPara>
>  <flowPara>second<emphasis>bold</emphasis> text</flowPara>
>  <flowPara>third text</flowPara>
>Basically I need to select nodes between nodes in a "flat" data 
>progression. I can think of some ugly approaches that would 
>accomplish this but it seems I should be able to use "<<" and ">>" 
>to select nodes between occurrences of <br/>. However, no matter how 
>I attempt to use these operators the result is a syntax error with 
>"<" being illegal.
>Can anyone point me to an example of how I can unflatten this xml?

This has come up before and it comes up in the classroom.  What you 
need to use here is grouping, creating new groups for every <br> and 
encapsulating everything in the group except <br> elements (which are 
the first in those groups that have a <br> and possibly not present 
in the very first group, as is true with your data).

I hope the working answer below helps.

. . . . . . . . . Ken

T:\ftemp>type steve.xml
<label>first text<br/>second<emphasis>bold</emphasis> text<br/>third 
T:\ftemp>xslt2 steve.xml steve.xsl
<?xml version="1.0" encoding="UTF-8"?>
    <flowPara>first text</flowPara>
    <flowPara>second<emphasis>bold</emphasis> text</flowPara>
    <flowPara>third text</flowPara>
T:\ftemp>type steve.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl=""

<xsl:output indent="yes"/>

<xsl:template match="label">
     <xsl:for-each-group select="node()" group-starting-with="br">
         <xsl:copy-of select="current-group()[not(self::br)]"/>


UBL and Code List training:      Copenhagen, Denmark 2010-02-08/10
XSLT/XQuery/XPath training after 2010-03-15/19
XSLT/XQuery/XPath training:   San Carlos, California 2010-04-26/30
Vote for your XML training:
Crane Softwrights Ltd.
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:
Video overview:
G. Ken Holman                 mailto:gkholman@C...
Male Cancer Awareness Nov'07
Legal business disclaimers:

XSL-List info and archive:
To unsubscribe, go to:
or e-mail: <mailto:xsl-list-unsubscribe@l...>


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.