Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <xsl:transform version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- >
- <!-- merge sibling elements, maybe separated with blankspace text nodes -->
- <xsl:template match="*">
- <xsl:copy><xsl:copy-of select="@*"/><xsl:apply-templates/></xsl:copy>
- </xsl:template>
- <xsl:template match="text()[not( normalize-space() )]" mode="merge"/>
- <xsl:template match="text()[not( normalize-space() )][ following-sibling::node()[1][self::spoj] ]" mode="merge">
- <xsl:text> </xsl:text>
- </xsl:template>
- <xsl:template match="spoj" mode="merge">
- <xsl:apply-templates/>
- </xsl:template>
- <xsl:template name="merge">
- <!-- recursive for the all following siblings in the group -->
- <xsl:apply-templates select="." mode="merge"/>
- <xsl:for-each select="following-sibling::node()[1][ self::text()[not(normalize-space())] or self::spoj ]">
- <xsl:call-template name="merge"/>
- </xsl:for-each>
- </xsl:template>
- <!-- skip merged -->
- <xsl:template match="text()[ preceding-sibling::node()[1]/self::spoj ][ following-sibling::node()[1]/self::spoj ][not(normalize-space())]"/>
- <xsl:template match="spoj" />
- <!-- the first 'spoj' in the group -->
- <xsl:template match="spoj[preceding-sibling::node()[1][ self::text()[normalize-space()] or self::*[ not(self::spoj )] ] ]">
- <expression>
- <xsl:call-template name="merge"/>
- </expression>
- </xsl:template>
- <xsl:output
- encoding="UTF-8"
- indent="yes"
- method="xml"
- />
- </xsl:transform>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement