[Home] [By Thread] [By Date] [Recent Entries]
At 2009-10-16 13:04 -0700, M C wrote:
How do I transform this input document: 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>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></xsl:stylesheet> T:\ftemp>
|

Cart



