Subject: RE: [xsl] Debug/QC Stylesheets From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Wed, 4 Jun 2008 16:37:46 +0100 |
Try something like this: <xsl:template match="*"> <xsl:for-each-group group-adjacent="if (*) then position() else node-name()"> <xsl:choose> <xsl:when test="current-grouping-key() instance of xs:integer"> <xsl:value-of select="name()"/> <xsl:apply-templates/> </xsl:when> <xsl:otherwise> <xsl:value-of select="count(current-group()), concat(name(), 's'[count(current-group()) ne 1])"/> </xsl:otherwise. </xsl:choose> (plus some formatting of course). The basic idea is to print the names of all the non-leaf elements, and a summary for a consecutive group of leaf elements with the same name. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Nic Gibson [mailto:nicg@xxxxxxxxxx] > Sent: 04 June 2008 16:00 > To: xsl-list > Subject: [xsl] Debug/QC Stylesheets > > Good afternoon > > Quick intro: I'm new here, I'm nic, I abuse and manipulate > data (often in XML) for a living, right now I work for Penguin Books. > > I have a debug stylesheet I use to give me a quick overview > of xml we get in from data converters. Right now, it dumps > out an html list containing the large scale structure of the > xml (it's a DocBook 5 > variant) down to chapter level. Below that level it counts > various elements (paras, blockquotes, sections, etc). Our QC > people use this script too. This morning, one of them asked > me if I could update it so that, rather than outputting > something like: > > chapter: > 24 paragraphs > 3 sections > 2 tables > > it could output something like: > > 3 paragraphs > 1 section > 2 paragraphs > 1 table > 3 paragraphs > > That is it would output the fact that the document contains 3 > paras then 1 section (which contains 2 paras) then 1 table > then 3 more paras. > > Initially, I thought 'dead easy' then I had a bit more of a > think and realised that it probably isn't. Right now, I just > use something like > count(descendant::para) get my output. Obviously, that no > longer works. Then, I thought that I could probably use > following-sibling to get the requested output. Then I > realised that it's not that simple either. > > So, the question. Am I wandering down a path that might be > easier to traverse using DOM or SAX? If not, can anyone point > me in the direction of something similar or suggest an > approach? I have a suspicion that I'm missing something obvious. > > cheers > > nic > -- > Nic Gibson > Director, Corbas Consulting > Editorial and Technical Consultancy > http://www.corbas.co.uk/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Debug/QC Stylesheets, Nic Gibson | Thread | Re: [xsl] Debug/QC Stylesheets, Nic Gibson |
Re: [xsl] why: first mode, then mat, David Carlisle | Date | [xsl] <xsl:apply-imports> and rules, Johannes Neubauer |
Month |