xsl-list
[Top] [All Lists]

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

2010-01-08 16:24:20
Thanks Ken - that's where I figured I needed to go with it. Will do. Hope all 
is well with you.
Steve

-----Original Message-----
From: G. Ken Holman [mailto:gkholman(_at_)CraneSoftwrights(_dot_)com]
Sent: Friday, January 08, 2010 4:20 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Trying to select sibling nodes between two nodes

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
text</label>

I need to transform this into:

<label>
 <flowPara>first text</flowPara>
 <flowPara>second<emphasis>bold</emphasis> text</flowPara>
 <flowPara>third text</flowPara>
</label>

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 
text</label  >
T:\ftemp>xslt2 steve.xml steve.xsl
<?xml version="1.0" encoding="UTF-8"?>
<label>
    <flowPara>first text</flowPara>
    <flowPara>second<emphasis>bold</emphasis> text</flowPara>
    <flowPara>third text</flowPara>
</label>
T:\ftemp>type steve.xsl
<?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                 version="2.0">

<xsl:output indent="yes"/>

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

</xsl:stylesheet>
T:\ftemp>


--
UBL and Code List training:      Copenhagen, Denmark 2010-02-08/10
XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19
XSLT/XQuery/XPath training:   San Carlos, California 2010-04-26/30
Vote for your XML training:   http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



[CONFIDENTIALITY AND PRIVACY NOTICE]

Information transmitted by this email is proprietary to Medtronic and is 
intended for use only by the individual or entity to which it is addressed, and 
may contain information that is private, privileged, confidential or exempt 
from disclosure under applicable law. If you are not the intended recipient or 
it appears that this mail has been forwarded to you without proper authority, 
you are notified that any use or dissemination of this information in any 
manner is strictly prohibited. In such cases, please delete this mail from your 
records.
 
To view this notice in other languages you can either select the following link 
or manually copy and paste the link into the address bar of a web browser: 
http://emaildisclaimer.medtronic.com


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>