Re: [xsl] empty element question

Subject: Re: [xsl] empty element question
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 16 Oct 2009 16:15:20 -0400
At 2009-10-16 13:04 -0700, M C wrote:
How do I transform this input document:

    <p>string 1<lb/>string 2</p>

to this output document?

    <p>string 1</p>
    <p>string 2</p>

This is a very limited specification, so I tried to be as general as possible in the example below. You use only text, but what if you have other formatting? I've tried to accommodate that.

And I don't see the issue as an empty element issue, but as a content grouping issue.

The principle I've used below is to create groups starting with each line-break element, and put out each group using the parent element.

I hope this helps.

. . . . . . . . . . Ken

p.s. registration is still open for public XSLT/XQuery hands-on class November 2-6, 2009

T:\ftemp>type morgan.xml <div> <p>string 1<lb/>string 2</p> </div>

T:\ftemp>xslt2 morgan.xml morgan.xsl
<?xml version="1.0" encoding="UTF-8"?><div>
    <p>string 1</p><p>string 2</p>
T:\ftemp>type morgan.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="";

<xsl:template match="*[lb]">
  <!--remember where we are-->
  <xsl:variable name="this" select="."/>
  <!--determine all of the groups of nodes-->
  <xsl:for-each-group select="node()" group-starting-with="lb">
    <!--return to the node being copied-->
    <xsl:for-each select="$this">
        <xsl:apply-templates select="@*"/>
        <!--but only copy that content not including the break-->
        <xsl:apply-templates select="current-group()[not(self::lb)]"/>

<xsl:template match="@*|node()"><!--identity for all other nodes-->
    <xsl:apply-templates select="@*|node()"/>



-- Upcoming: hands-on code list, UBL, XSLT, XQuery and XSL-FO classes in Copenhagen Denmark and Washington DC USA, October/November 2009 Interested in other classes? Crane Softwrights Ltd. Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: Video overview: G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 Legal business disclaimers:

Current Thread