Stylesheet hierarchy, xslt

Processing Stylesheets

1. Visualisation of a stylesheet hiearachy
2. dependency map of stylesheets

1.

Visualisation of a stylesheet hiearachy

DaveP

This produces a .dot file, suitable for graphviz, which can produce SVG or various other formats.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.1">
 <xsl:param name="root" select="'root'"/>
<d:doc xmlns:d="rnib.org.uk/tbs#">
 <revhistory>
   <purpose><para>This stylesheet works with *.xsl to produce *.dot for
graphviz processing</para></purpose>
   <revision>
    <revnumber>1.0</revnumber>
    <date> 2003</date>
    <authorinitials>DaveP</authorinitials>
    <revdescription>
     <para></para>
    </revdescription>
    <revremark></revremark>
   </revision>
  </revhistory>
  </d:doc>
  

  <xsl:output method="text"/>



  <xsl:template match="xsl:stylesheet">
    digraph G{
  

    <xsl:if test="not(*[self::xsl:include or self::xsl:import])">
      NoImportsOrIncludes;
    </xsl:if>
    <xsl:apply-templates select="*[self::xsl:include or self::xsl:import]">
      <xsl:with-param name='src' select="translate($root,'.','_')"/>
    </xsl:apply-templates>
    <xsl:text>&#10;}</xsl:text>
  </xsl:template>




  <xsl:template match="xsl:include">
    <xsl:param name="src" select="'none'"/>
    <xsl:message>
include      <xsl:value-of select="@href"/>
    </xsl:message>
    <xsl:value-of select="concat('&#10;',$src,' -> ')"/>

    <xsl:value-of select="concat('&quot;',@href,'&quot;')"/>
[label="(include)"]; &#10;<xsl:text> </xsl:text>
    <xsl:choose>
      <xsl:when test="following-sibling::*[self::xsl:include or
                      self::xsl:import][1]">
        <xsl:value-of select="' '"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="' '"/>
        </xsl:otherwise>
      </xsl:choose>

      <xsl:apply-templates
        select="document(@href)/xsl:stylesheet/*[self::xsl:include or
                self::xsl:import]"/>

  </xsl:template>

  <xsl:template match="xsl:import">
    <xsl:value-of select="substring-before(@href,'.')"/> [label="(import)"]


      <xsl:choose>
        <xsl:when test="following-sibling::*[self::xsl:include or
self::xsl:import][1]">
          <xsl:value-of select="'->'"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="';'"/>
        </xsl:otherwise>
      </xsl:choose>

    <xsl:apply-templates
      select="document(@href)/xsl:stylesheet/*[self::xsl:include or
              self::xsl:import]"/>
  </xsl:template>



  <xsl:template match="*">
    *****<xsl:value-of select="name(..)"/>/<xsl:value-of
select="name()"/>******
</xsl:template>


</xsl:stylesheet>

2.

dependency map of stylesheets

Américo Albuquerque



> Does anyone know of a tool that can generate a dependency map 
> of a whole set of XSL's ? (i.e. which stylesheets import others, etc.)

> A tool that generated some kind of site map/tree of related 
> XSLs would be great as I'm trying to clean up and reign in 
> some 400 files with a view to finding common dependencies, etc.

You could do that with xslt.

Try these templates:

  <xsl:template match="xsl:stylesheet">
    <xsl:text>Mappings&#10;</xsl:text>
    <xsl:text>--+&#10;</xsl:text>
    <xsl:text>&#160;&#160;|&#10;</xsl:text>
    <xsl:apply-templates select="*[self::xsl:include or self::xsl:import]"/>
    <xsl:text>&#10;</xsl:text>
  </xsl:template>

  <xsl:template match="xsl:include">
    <xsl:param name="sep" select="'&#160;&#160;'"/>
    <xsl:variable name="nxt">
      <xsl:choose>
        <xsl:when test="following-sibling::*[self::xsl:include or
self::xsl:import][1]">
          <xsl:value-of select="'|'"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="'&#160;'"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:value-of select="concat($sep,'|&#10;')"/>
    <xsl:value-of select="concat($sep,'+-')"/>
    <xsl:value-of select="@href"/>
    <xsl:text> (include)</xsl:text>
    <xsl:text>&#10;</xsl:text>
    <xsl:apply-templates
select="document(@href)/xsl:stylesheet/*[self::xsl:include or
self::xsl:import]">
      <xsl:with-param name="sep" select="concat($sep,$nxt,'&#160;')"/>
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="xsl:import">
    <xsl:param name="sep" select="'&#160;&#160;'"/>
    <xsl:variable name="nxt">
      <xsl:choose>
        <xsl:when test="following-sibling::*[self::xsl:include or
self::xsl:import][1]">
          <xsl:value-of select="'|'"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="'&#160;'"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:value-of select="concat($sep,'|&#10;')"/>
    <xsl:value-of select="concat($sep,'+-')"/>
    <xsl:value-of select="@href"/>
    <xsl:text> (import)</xsl:text>
    <xsl:text>&#10;</xsl:text>
    <xsl:apply-templates
select="document(@href)/xsl:stylesheet/*[self::xsl:include or
self::xsl:import]">
      <xsl:with-param name="sep" select="concat($sep,$nxt,'&#160;&#160;')"/>
    </xsl:apply-templates>
  </xsl:template>