[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Stylesheet analysis/documentation


Subject: Re: [xsl] Stylesheet analysis/documentation
From: davep <davep@xxxxxxxxxxxxx>
Date: Sat, 17 Mar 2012 10:18:47 +0000

On 17/03/12 08:18, Andrew Welch wrote:

Ken's "XSLStyle" might be something like you're after.  Here's a post
from Florent about it:
http://fgeorges.blogspot.co.uk/2009/02/xslstyle-and-oxygen.html
Looking at the first commentor, you might already be aware of that :)

IIRC Kens is about documenting what you have written? I'm more interested in understanding what others have written?

First cut below. GPL
If you can improve it, please share.
I'm looking initially at fo output... ymmv

DaveP


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:d="http://www.dpawson.co.uk/ns#" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo xs d" version="2.0">

<d:doc xmlns:d="http://www.dpawson.co.uk/ns#">
<d:revhistory>
<d:purpose>
<d:para>This stylesheet works with a {} file to produce a {}</d:para>
</d:purpose>
<d:revision>
<d:revnumber>1.0</d:revnumber>
<d:date>2012-03-17T07:54:29Z.</d:date>
<d:authorinitials>DaveP</d:authorinitials>
<d:revdescription>
<d:para>Analyse a stylseheet set</d:para>
</d:revdescription>
<d:revremark></d:revremark>
</d:revision>
</d:revhistory>
</d:doc>


<xsl:strip-space elements="*"/>
  <xsl:output method="html" indent="yes" encoding="utf-8"/>

<xsl:template match="/">
<html>
<head>
<title>Stylesheet analysis. Stylesheet <xsl:value-of select="document-uri(/)"/></title>
<link rel="STYLESHEET" href="analyze.css" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body bgcolor="#FFFFFF">
<h2>Stylesheet analysis. Revision <xsl:value-of


select="document('')//d:doc/d:revhistory/d:revision[last()]/d:revnumber"/></h2>

      <h3>Stylesheet <xsl:value-of select="document-uri(.)"/></h3>
      <xsl:call-template name='toc'/>
      <xsl:apply-templates/>
    </body>
    </html>
  </xsl:template>


<!-- toc --> <xsl:template name="toc"> <xsl:if test="//xsl:template"> <h3>Templates</h3> <ul> <ul> <xsl:for-each select="//xsl:template"> <li><a href="#{generate-id()}"> <xsl:choose> <xsl:when test="@match"> <xsl:value-of select="@match"/> </xsl:when> <xsl:otherwise> <xsl:text>name </xsl:text> <xsl:value-of select="@name"/> </xsl:otherwise> </xsl:choose> </a>

	</li>
      </xsl:for-each>
    </ul>
  </ul>
</xsl:if>
</xsl:template>

<!-- imports -->
<xsl:template match="xsl:import">
<xsl:variable name="path" select="tokenize(@href,'/')[last()]"/>
<div class="import" id="generate-id()">
<p><a href="{concat($path,'.html')}"><xsl:value-of select="@href"/></a></p>
</div>
<xsl:result-document
    href="{concat($path,'.html')}">
  <xsl:apply-templates select="document(@href)"/>
</xsl:result-document>
</xsl:template>

<!-- Match templates -->
<xsl:template match="xsl:template[@match][not(@name)]">
<div class="match" id="{generate-id()}">
<p>Match Template <b><xsl:value-of select="@match"/></b>
<xsl:if test="@mode">
<xsl:text> </xsl:text>
<span class="mode"><xsl:value-of select="@mode"/></span>
</xsl:if>
</p>
<xsl:if test=".//*[@xsl:use-attribute-sets]">
<xsl:apply-templates select=".//*[@xsl:use-attribute-sets]" mode='uas'/>
</xsl:if>
</div>
<xsl:apply-templates/>
</xsl:template>


<!-- Named templates -->
<xsl:template match="xsl:template[@name][not(@match)]">
<div class='named'  id="{generate-id()}">
<p>Named Template  <b><xsl:value-of select="@name"/></b>
    <xsl:if test="@mode">
      <xsl:text>  </xsl:text>
      <span class="mode"><xsl:value-of select="@mode"/></span>
    </xsl:if>

</p>
<xsl:if test=".//*[@xsl:use-attribute-sets]">
<xsl:apply-templates select=".//*[@xsl:use-attribute-sets]" mode='uas'/>
</xsl:if>


</div>
<xsl:apply-templates/>
</xsl:template>

<!-- Match named templates -->
<xsl:template match="xsl:template[@match][@name]">
<div class="match" id="{generate-id()}">
<p>Match Template <b><xsl:value-of select="@match"/></b>
<xsl:if test="@mode">
<xsl:text> </xsl:text>
<span class="mode"><xsl:value-of select="@mode"/></span>
</xsl:if>
</p>
<p>Named Template <b><xsl:value-of select="@name"/></b></p>
<xsl:if test=".//*[@xsl:use-attribute-sets]">
<xsl:apply-templates select=".//*[@xsl:use-attribute-sets]" mode='uas'/>
</xsl:if>
</div>
<xsl:apply-templates/>
</xsl:template>




<!-- Attribute sets. Moded, to use within templates -->

<xsl:template match="fo:*[@xsl:use-attribute-sets]" mode='uas'>

  <xsl:variable name="parentmatch"
		select="ancestor::*[self::xsl:template][1]/@match,''" />
  <xsl:variable name="parentname"
		select="ancestor::*[self::xsl:template][1]/@name,''" />

<div class="attribute-set-use" id="{generate-id()}">
<p class="attribute-set-use" id="{generate-id()}">
use-attribute-set <b><xsl:value-of select="@xsl:use-attribute-sets"/></b></p>
</div>
</xsl:template>



<!-- variables --> <xsl:template match="xsl:variable"> <div class="variable" id="{generate-id()}"> <p>Variable <b><xsl:value-of select="@name"/></b></p> </div> </xsl:template>



<!-- keys -->
<xsl:template match="xsl:key">
<div class='keydef' id="generate-id()">
<p>Key, name=<xsl:value-of select="@name"/></p>
</div>
</xsl:template>


<!-- Ignore xsl:text --> <xsl:template match="xsl:text"/>

<!-- Ignore xsl:attribute?? -->
<xsl:template match="xsl:attribute[not(@xsl:use-attribute-sets)]"/>

<!-- Ignore xsl:param -->
<xsl:template match="xsl:param|xsl:with-param"/>

<!-- Ignore xsl:when,xsl:otherwise if contains text only? -->
<xsl:template match="xsl:when[text()][not(*)]"/>
<xsl:template match="xsl:otherwise[text()][not(*)]"/>



<!-- Default -->
 <xsl:template match="*">
   <xsl:apply-templates/>
 </xsl:template>


</xsl:stylesheet>



<!-- * Copyright (C) 2012 Dave Pawson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA.

-->

/*CSS for the output of analyze.xsl*/

div.match p b{
background-color: aliceblue;
 }

div.variable{
  text-indent: 2em;
 }
div.variable p b{
  background-color: ghostwhite;
 }

div.attribute-set-use{
text-indent: 2em;
 }

span.mode:before{
content:"Mode ";
background-color:ghostwhite;
 }

span.mode{
background-color:lemonchiffon;
 }




regards


--
Dave Pawson
XSLT XSL-FO FAQ.
http://www.dpawson.co.uk


Current Thread
Keywords