[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Join elements by name, with spaces in between
Michael Kay schrieb:
Try group-adjacent using a grouping key of Thank you very much for this expression that would have taken me weeks to come up with... You are right that I want to include spaces in an element only if the space was formerly between instances of the same element, so I have expanded the conditional expression as follows (sorry for the mangled indentation): <xsl:template match="e"> <xsl:copy> <xsl:for-each-group select="node()" group-adjacent="if (. instance of element()) then name(.) else (if (name(preceding-sibling::*[1]) eq name(following-sibling::*[1])) then name(preceding-sibling::*[1]) else 'space_outside')"> <xsl:element name="name(current-group()[1])"> <xsl:apply-templates select="current-group()/text()"/> </xsl:element> </xsl:for-each-group> </xsl:copy> </xsl:template> So far I haven't been able to test if it works because I don't know how to dynamically set the "new" element's name in xsl:element from the element which is the "leader" of the current group. Am I going the wrong way about joining instances of the same element type? To recall, I want to transform this <e><x>x</x> <a>a1</a> <a>a2</a> <b>b</b> <c>c1</c> <c>c2</c> <a>a3</a></e> into this: <e><x>x</x> <a>a1 a2</a> <b>b</b> <c>c1 c2</c> <a>a3</a></e> Yves
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|