[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Group problem with blank elements
If the statement-message elements that you want to group all have the same parent node, you can just take the text value of each of them. The following XML (yours with a parent element added): <x> <statement-message>Your account is now seriously in arrears. To </statement-message> <statement-message>avoid further action a payment of </statement-message> <statement-message>$82.00 is required immediately. Any </statement-message> <statement-message>purchases will now be declined.</statement-message> <statement-message></statement-message> <statement-message> More text </statement-message> <statement-message></statement-message> <statement-message></statement-message> <statement-message></statement-message> </x> when processed with the following XSL: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="x"> <xsl:apply-templates/> </xsl:template> <xsl:template match="statement-message[1]"> <statement-message> <xsl:for-each select="../statement-message"> <xsl:apply-templates/> </xsl:for-each> </statement-message> </xsl:template> <xsl:template match="statement-message[not(position() = 1)]"/> </xsl:stylesheet> produces the following output: <?xml version="1.0" encoding="UTF-8"?> <statement-message>Your account is now seriously in arrears. To avoid further action a payment of $82.00 is required immediately. Any purchases will now be declined. More text </statement-message> It's a very limited solution, because it works only when each message you want to output is contained in a set of statement-message nodes with a distinct parent element for each output message. If you need to create two output messages from a single run of statement-message nodes, this method won't work. Still, limited though it is, it does work for some cases. Maybe it'll work for you (if the way your document is constructed permits it - no way to tell from what you posted). If not, you'll need to post more detail about your source document (specifically the parent and sibling elements but also the child elements, if any). That's why it's best to show a short-but-complete document rather than a fragment. Jay Bryant Bryant Communication Services (presently consulting at Synergistic Solution Technologies) "Ed Yau" <eyau@xxxxxxxxxxxxxxx> 06/30/2005 12:30 PM Please respond to xsl-list@xxxxxxxxxxxxxxxxxxxxxx To <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> cc Subject Group problem with blank elements Hiya, Having loads of trouble with this. On the face of it a really easy problem. I have a bunch of elements like so: <statement-message>Your account is now seriously in arrears. To</statement-message> <statement-message>avoid further action a payment of</statement-message> <statement-message>$82.00 is required immediately. Any</statement-message> <statement-message>purchases will now be declined.</statement-message> <statement-message> </statement-message> <statement-message> More text </statement-message> <statement-message> </statement-message> <statement-message> </statement-message> <statement-message> </statement-message> I want to strip out the empty tags and merge adjacent elements as follows: <statement-message> Your account is now seriously in arrears. To avoid further action a payment of 82.00 is required immediately. Any purchases will now be declined.</statement-message> <statement-message> More text </statement-message> My code at the moment is: <xsl:for-each-group select="statement-message" group-ending-with="statement-message[string-length(normalize-space(follo wing-sibling::statement-message[1]))=0]"> <statement-message> <xsl:value-of select="."/> </statement-message> </xsl:for-each-group> My understanding of this is that it should start grouping from the 1st statement message, with the groups ending as soon as an empty element is reached. The empty tags at the end would still be there, but at least it should do the merge. However, the result looks like: <statement-message>Your account is now seriously in arrears. To</statement-message> <statement-message> </statement-message> <statement-message> More text </statement-message> <statement-message> </statement-message> <statement-message> </statement-message> <statement-message> </statement-message> So where am I going wrong? Ed
|
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
|