Subject: RE: [xsl] How to mark every 5th output record. From: "Patrick Bergeron" <pbergeron@xxxxxxxxxxx> Date: Tue, 11 Mar 2008 10:03:49 -0400 |
Hmm. I guess I was trying to reduce the question to aim for the kind of answer I was looking for. As I said the rules under which I process my list are quite complex. So much so that my XSLT stylesheet is over 2900 lines of code (and yes, that's just nuts). Different records (and types of records) are processed using different rules, other records are deferred for later processing, others merged together to produce a final one, some are skipped altogether, some complex operations are performed on yet another set of records, etc. The output file format is crazy, and the spec for the file format is about as obscure and obtuse as I have ever seen in 20 years programming. But in the end, I end up with a text file that has 1 line per "output record", but these "output records" have almost nothing to do with the input records, and I need to separate them with a marker every 5th. I can't really do (position() mod 5) on my original input data because it has no correlation to the order of the output records, and it's impossible to create an expression that would select them properly in the order I need. Is my only option to create another tree that contains all of my output record results, and then iterate over that tree once again, and putput the same data verbatim, only this time insert a marker every 5th? Gheesh, talk about using a tank to shoot a bird. I'm trying to avoid doing this for other reasons: 1) My input data set is quite large. 2) The XSLT processor is running on an embedded platform with limited memory. 3) I'm already paying the price of doing a copy of the data in an earlier pass, I'd like to not pay the price again. Is there really, really, really _any_ other way of doing this without making a 3rd copy of my data set? Regards Patrick Bergeron -----Original Message----- From: Michael Kay [mailto:mike@xxxxxxxxxxxx] Sent: Tuesday, March 11, 2008 4:33 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] Easy question, big headache. > > And I need to output some of these records, but not all of > them. The rules upon which I decide to output are complex, > and I won't bore you with the details. Unfortunately it all depends on the detail. If you can express the rules in an XPath expression EXP, then you can do: <xsl:for-each select="record[EXP]"> <xsl:copy-of select="."/> <xsl:if test="position() mod 5 = 0"> <marker/> </xsl:if> </xsl:for-each> In XSLT 2.0 this always works - because EXP can call a stylesheet function that can do any computation you like. In 1.0 it rather depends on EXP. > > In any other language, it's easy easy: > Writing in a language you know is always easier than in one that's new! Michael Kay http://www.saxonica.com/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Easy question, big headac, Michael Kay | Thread | Re: [xsl] How to mark every 5th out, David Carlisle |
RE: [xsl] Easy question, big headac, Michael Kay | Date | Re: [xsl] How to mark every 5th out, David Carlisle |
Month |