|
Subject: [xsl] Allowing whitespace to stop merge of adjacent nodes From: Matt Sims <matt.sims@xxxxxxxx> Date: Tue, 10 Oct 2006 11:39:12 +0100 |
I'm using the following stylesheet to merge adjacent nodes of a particular type and sum their attributes:
<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aston="http://www.aston.tv/schemas/Aston/Aston7">
<xsl:template match="node()">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()[1]"/>
</xsl:copy>
<xsl:apply-templates select="following-sibling::node()[1]"/>
</xsl:template> <xsl:template match="aston:offset[not(node())]">
<xsl:param name="a" select="/.."/>
<xsl:choose>
<xsl:when test="following-sibling::node()[self::* or
normalize-space(.)][1]/self::aston:offset[not(node())]">
<xsl:apply-templates
select="following-sibling::aston:offset[1]">
<xsl:with-param name="a" select="$a|@*"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<offset xmlns="http://www.aston.tv/schemas/Aston/Aston7"
x="{sum($a[name()='x']|@x)}" y="{sum($a[name()='y']|@y)}"
z="{sum($a[name()='z']|@z)}" />
<xsl:apply-templates select="following-sibling::node()[1]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template><text> Hello<offset x="2" y="4" /><offset x="3" y="2" />World </text>
<text> Hello<offset x="5" y="6" />World </text>
My problem occurs if I have a whitespace character between the two adjacent nodes, like so:
<text> Hello<offset x="2" y="4" /> <offset x="3" y="2" />World </text>
In this case, I wouldn't expect the nodes to be merged as they're not strictly adjacent (there's a whitespace node between them) - but they are!
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Finding referenced / refe, David Carlisle | Thread | RE: [xsl] Allowing whitespace to st, Michael Kay |
| Re: [xsl] Finding referenced / refe, David Carlisle | Date | RE: [xsl] XSLT functions in XPath, Michael Kay |
| Month |