|
Subject: Re: [xsl] empty element question From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 16 Oct 2009 16:15:20 -0400 |
How do I transform this input document:
<div> <p>string 1<lb/>string 2</p> </div>
to this output document?
<div> <p>string 1</p> <p>string 2</p> </div>
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>
</div>
T:\ftemp>type morgan.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"><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:copy>
<xsl:apply-templates select="@*"/>
<!--but only copy that content not including the break-->
<xsl:apply-templates select="current-group()[not(self::lb)]"/>
</xsl:copy>
</xsl:for-each>
</xsl:for-each-group>
</xsl:template><xsl:template match="@*|node()"><!--identity for all other nodes-->
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
-- 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? 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@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] empty element question, M C | Thread | RE: [xsl] empty element question, Michael Kay |
| [xsl] empty element question, M C | Date | RE: [xsl] empty element question, Michael Kay |
| Month |