xsl-list
[Top] [All Lists]

Re: [xsl] Debug/QC Stylesheets

2008-06-04 08:43:16
Ahhh.
I really should have thought of grouping.
(fx: smacks head)

thanks

nic

On 4 Jun 2008, at 16:37, Michael Kay wrote:

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(_at_)corbas(_dot_)net]
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/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>