i can't find working solution problem. need merge 2 elements same name 1 when in specific position in document: tags hi when between them stays lb break='no'. how can that? xml code is:
<p> <lb n="28"/> lorem ipsum dolor sit <lb n="29"/> amet, consectetur, <hi rend="u">adi</hi> <lb n="30" break="no"/><hi rend="u">pisci</hi> elit... </p>
i transform floating text without line breakes , there hyphen there need merge 2 elements one. blank between them.
<p>lorem ipsum dolor sit amet, consectetur <span class="u">adipisici</span> elit...</p>
thanks lot!
assuming xslt 2.0 processor saxon 9 or xmlprime can use
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:xs="http://www.w3.org/2001/xmlschema" exclude-result-prefixes="xs"> <xsl:template match="p"> <xsl:copy> <xsl:for-each-group select="node() except text()[not(normalize-space())]" group-adjacent="self::hi or self::lb[@break = 'no']"> <xsl:choose> <xsl:when test="current-grouping-key()"> <span class="{current-group()[self::hi][1]/@rend}"> <xsl:apply-templates select="current-group()/node()"/> </span> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:copy> </xsl:template> </xsl:stylesheet>
to transform
<p> <lb n="28"/> lorem ipsum dolor sit <lb n="29"/> amet, consectetur, <hi rend="u">adi</hi> <lb n="30" break="no"/><hi rend="u">pisci</hi> elit... </p>
into
<p> lorem ipsum dolor sit amet, consectetur, <span class="u">adipisci</span> elit... </p>
Comments
Post a Comment