SHOW:
|
|
- or go back to the newest paste.
| 1 | <?xml version="1.0" encoding="UTF-8"?> | |
| 2 | <xsl:transform version="1.0" | |
| 3 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
| 4 | > | |
| 5 | ||
| 6 | - | <!-- merge sibling elements, maybe separated with blankspace nodes --> |
| 6 | + | <!-- merge sibling elements, maybe separated with blankspace text nodes --> |
| 7 | ||
| 8 | <xsl:template match="*"> | |
| 9 | <xsl:copy><xsl:copy-of select="@*"/><xsl:apply-templates/></xsl:copy> | |
| 10 | </xsl:template> | |
| 11 | ||
| 12 | - | <xsl:template match="text()[not( normalize-space() )]" mode="greek"/> |
| 12 | + | |
| 13 | <xsl:template match="text()[not( normalize-space() )]" mode="merge"/> | |
| 14 | - | <xsl:template match="text()[not( normalize-space() )][ following-sibling::node()[self::spoj] ]" mode="greek"> |
| 14 | + | |
| 15 | <xsl:template match="text()[not( normalize-space() )][ following-sibling::node()[1][self::spoj] ]" mode="merge"> | |
| 16 | <xsl:text> </xsl:text> | |
| 17 | </xsl:template> | |
| 18 | - | <xsl:template match="spoj" mode="greek"> |
| 18 | + | |
| 19 | <xsl:template match="spoj" mode="merge"> | |
| 20 | <xsl:apply-templates/> | |
| 21 | </xsl:template> | |
| 22 | - | <xsl:template match="defpozn"> |
| 22 | + | |
| 23 | - | <comment><xsl:copy-of select="@*"/> |
| 23 | + | <xsl:template name="merge"> |
| 24 | - | <xsl:copy-of select="node()[1][self::text()]"/> |
| 24 | + | <!-- recursive for the all following siblings in the group --> |
| 25 | - | <xsl:if test="spoj"> |
| 25 | + | <xsl:apply-templates select="." mode="merge"/> |
| 26 | - | <expression> |
| 26 | + | <xsl:for-each select="following-sibling::node()[1][ self::text()[not(normalize-space())] or self::spoj ]"> |
| 27 | - | <xsl:apply-templates select=" spoj[1] | spoj[1]/following-sibling::node()" mode="greek"/> |
| 27 | + | <xsl:call-template name="merge"/> |
| 28 | - | </expression> |
| 28 | + | </xsl:for-each> |
| 29 | - | </xsl:if> |
| 29 | + | |
| 30 | - | </comment> |
| 30 | + | |
| 31 | ||
| 32 | <!-- skip merged --> | |
| 33 | - | <xsl:template match="defpozn[ *[ not(self::spoj)] ] | defpozn[ spoj[1]/following-sibling::text()[ normalize-space() ] ] "> |
| 33 | + | <xsl:template match="text()[ preceding-sibling::node()[1]/self::spoj ][ following-sibling::node()[1]/self::spoj ][not(normalize-space())]"/> |
| 34 | - | <xsl:message terminate="yes"> |
| 34 | + | <xsl:template match="spoj" /> |
| 35 | - | <xsl:text>Not supported:</xsl:text> |
| 35 | + | |
| 36 | - | <xsl:copy-of select="."/> |
| 36 | + | <!-- the first 'spoj' in the group --> |
| 37 | - | </xsl:message> |
| 37 | + | <xsl:template match="spoj[preceding-sibling::node()[1][ self::text()[normalize-space()] or self::*[ not(self::spoj )] ] ]"> |
| 38 | <expression> | |
| 39 | <xsl:call-template name="merge"/> | |
| 40 | </expression> | |
| 41 | </xsl:template> | |
| 42 | ||
| 43 | ||
| 44 | <xsl:output | |
| 45 | encoding="UTF-8" | |
| 46 | indent="yes" | |
| 47 | method="xml" | |
| 48 | /> | |
| 49 | ||
| 50 | </xsl:transform> |