[Home] [By Thread] [By Date] [Recent Entries]
Michael Kay schrieb:
Try group-adjacent using a grouping key of Matching the whitespace nodes in between two element instances seems to be rather difficult, so now I try to group my text nodes with the *preceding* element (grouping with the following element fails, obviously because sometimes there is no following element node) and move the spaces out again later. I am using these templates (moving the spaces out is to be done later): <xsl:template match="entry">
<xsl:copy>
<xsl:for-each-group select="node()"
group-adjacent="if (. instance of element()) then name(.) else
name(preceding-sibling::*[1])">
<xsl:element name="{name(current-group()[1])}">
<xsl:apply-templates select="current-group()/text()"/>
</xsl:element>
</xsl:for-each-group>
</xsl:copy>
</xsl:template><xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>This works, short of an important detail - it eats up all whitespace, but I don't know why :-(. So given my input of <e><x>x</x> <a>a1</a> <a>a2</a> <b>b</b> <c>c1</c> <c>c2</c> <a>a3</a></e> I get <e><x>x</x><a>a1a2</a><b>b</b><c>c1c2</c><a>a3</a></e> instead of <e><x>x</x> <a>a1 a2</a> <b>b</b> <c>c1 c2</c> <a>a3</a></e> What might be the reason for this? Yves
|

Cart



