Subject: [xsl] For-each-group ordering problem From: "Ed Yau" <eyau@xxxxxxxxxxxxxxx> Date: Fri, 11 Apr 2008 13:15:18 +0100 |
Hello all, I'm wondering how to work around this. I'm trying to parse wordml documents to pull out the text. The ordering of the text is very important as it has to read the same as the original. In the main, my stylesheet works perfectly apart from 1 interesting aspect. When the text contained in a w:t is duplicated (i.e. the text appears more than once), for-each-group seems to put all the duplicates together rather than leaving the order as in the original. This is a major limitation. I include an cutdown example below in the hope that someone may advise me how to proceed. I'm thinking the solution must lie with using xsl:sort in the for-each-group, but I'm baffled as to what to sort on. Any help would be very gratefully received. Many thanks, Ed Here is a sample of my source XML. <wx:sect> <w:p> <w:pPr> <w:rPr> <w:sz-cs w:val="40"/> </w:rPr> </w:pPr> <w:r> <w:t>This is a CD recording for:</w:t> </w:r> </w:p> <w:p> <w:pPr> <w:rPr> <w:sz-cs w:val="40"/> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:sz-cs w:val="40"/> </w:rPr> <w:t>Mr A Customer</w:t> </w:r> </w:p> <w:p> <w:pPr> <w:rPr> <w:sz-cs w:val="40"/> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:sz-cs w:val="40"/> </w:rPr> <w:t>Texas</w:t> </w:r> </w:p> <w:p> <w:pPr> <w:rPr> <w:sz-cs w:val="40"/> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:sz-cs w:val="40"/> </w:rPr> <w:t>HX1 5TX</w:t> </w:r> </w:p> <w:p/> <w:p> <w:pPr> <w:rPr> <w:sz-cs w:val="40"/> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:sz-cs w:val="40"/> </w:rPr> <w:t>For energy consumption at:</w:t> </w:r> </w:p> <w:p> <w:pPr> <w:rPr> <w:sz-cs w:val="40"/> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:sz-cs w:val="40"/> </w:rPr> <w:t>TEXAS</w:t> </w:r> </w:p> <w:p> <w:pPr> <w:rPr> <w:sz-cs w:val="40"/> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:sz-cs w:val="40"/> </w:rPr> <w:t>HX1 5TX</w:t> </w:r> </w:p> <w:sectPr> Here is my output XML: <?xml version="1.0" encoding="UTF-8"?> <jsml> <div type="paragraph"> <div type="sentence">This is a CD recording for:</div> <div type="sentence">Mr A Customer</div> <div type="sentence">Texas</div> <div type="sentence">HX1 5TXHX1 5TX</div> <!-- the second postal code should be at the end but it's not --> <div type="sentence">For energy consumption at:</div> <div type="sentence">TEXAS</div> </div> </jsml> Here is my stylesheet: <xsl:template match="/"> <jsml> <!-- sections --> <!-- each section starts with a bold element --> <xsl:for-each-group select="//w:p/w:r/w:t" group-starting-with="//w:p/w:r[../w:pPr/w:rPr/w:b][1]/w:t"> <div type="paragraph"> <!-- section text --> <xsl:for-each-group select="current-group()[not(../../w:pPr/w:rPr/w:b)]" group-by="../.."> <div type="sentence"> <xsl:for-each select="current-group()"> <xsl:value-of select="."/> </xsl:for-each> </div> <!-- sentences --> </xsl:for-each-group> </div> </xsl:for-each-group> </jsml> </xsl:template> Edmond Yau (VST - Software Development Manager) ext.204 01244 651904 01244 651909 fax eyau@xxxxxxxxxxxxxxx -- Vision Support Trading Web Site - www.vstrading.co.uk Registered Office: Beech House, Park West, Sealand Road, Chester, CH1 4RJ REGISTERED IN ENGLAND AND WALES. COMPANY NUMBER 3828782 Please note all electronic mail may be monitored. The information contained in or attached to this email is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are not authorised to and must not disclose, copy, distribute, or retain this message or any part of it. It may contain information which is confidential and/or covered by legal professional or other privilege (or other rules or laws with similar effect in jurisdictions outside England and Wales). The views expressed in this email are not necessarily the views of Vision Support Trading Ltd, and the company, its directors, officers or employees make no representation or accept any liability for its accuracy or completeness unless expressly stated to the contrary.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Adding form elements capt, Aaron Johnson | Thread | Re: [xsl] For-each-group ordering p, David Carlisle |
Re: [xsl] Adding form elements capt, Aaron Johnson | Date | Re: [xsl] For-each-group ordering p, David Carlisle |
Month |