github.com/matislovas/ratago@v0.0.0-20240408115641-cc0857415a7a/xslt/testdata/general/bug-58.xsl (about)

     1  <?xml version="1.0" encoding="UTF-8"?>
     2  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     3     xmlns:msxsl="http://exslt.org/common" extension-element-prefixes="msxsl">
     4    <xsl:output method="html" version="1.0" encoding="iso-8859-1" indent="yes"/>
     5    
     6    <xsl:param name="document-name"/>
     7    
     8    <xsl:variable name="stylesheet-tree" >
     9      <stylesheet href="{$document-name}">
    10        <xsl:apply-templates select="/" mode="tree-building"/>
    11      </stylesheet>
    12    </xsl:variable>
    13    
    14    <xsl:template match="/">
    15      <html xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:spec="http://www.macaw.nl/namespaces/creaim/html-specials" xmlns:fml="http://www.macaw.nl/namespaces/creaim/formsML">
    16        <head>
    17          <title>Documentation for: <xsl:value-of select="$document-name"/></title>
    18          <link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style"/>
    19          <script >
    20            <xsl:comment>
    21              function toggleElm(elmid)
    22              {
    23                var elmstyle = document.all(elmid).style;
    24                //alert(document.all(elmid).nodeName);
    25                if (elmstyle.display == "none")
    26                {
    27                  elmstyle.display = "";
    28                }else{
    29                  elmstyle.display = "none";
    30                }
    31                //alert(elmstyle.display);
    32              }
    33            </xsl:comment>
    34          </script>
    35        </head>
    36        <body>
    37         <h1>Documentation for: <xsl:value-of select="$document-name"/></h1>
    38         <xsl:for-each select="xsl:stylesheet/preceding::comment()">
    39           <xsl:value-of select="self::comment()" disable-output-escaping="yes"/><br/>
    40         </xsl:for-each>
    41         <h2>Import/Include tree</h2>
    42        <xsl:call-template name="display-stylesheet-tree">
    43        </xsl:call-template>
    44         <h2>Parameters</h2>
    45        <xsl:apply-templates select="xsl:stylesheet/xsl:param"/>
    46         <h2>Global variables</h2>
    47        <xsl:apply-templates select="xsl:stylesheet/xsl:variable"/>
    48         <h2>Templates</h2>
    49        <xsl:apply-templates select="xsl:stylesheet/xsl:template"/>
    50         <h2>Other top-level elements</h2>
    51        <xsl:apply-templates select="xsl:stylesheet/xsl:decimal-format|xsl:stylesheet/xsl:atribute-set|xsl:stylesheet/xsl:key|xsl:stylesheet/xsl:output|xsl:stylesheet/xsl:namespace-alias|xsl:stylesheet/xsl:preserve-space|xsl:stylesheet/xsl:strip-space"/>
    52        </body>
    53      </html>
    54    </xsl:template>
    55    
    56    <xsl:template match="xsl:stylesheet/xsl:*">
    57    
    58    <a name="elmxsl_{translate(local-name(), ':.', '__')}|{@name}|{@match}"></a>
    59      <xsl:call-template name="display-xsl-element">
    60        <xsl:with-param  name="elm" select="self::*"/>
    61      </xsl:call-template>
    62      <xsl:if test="msxsl:node-set($stylesheet-tree)/stylesheet/stylesheet[@method='import']/descendant::xsl:*[name()=name(current())][@match=current()/@match][(@mode=current()/@mode) or (not(@mode) and not(current()/@mode))]">
    63         Overriding identical match pattern: <xsl:apply-templates select="msxsl:node-set($stylesheet-tree)/stylesheet/stylesheet[@method='import']/descendant::xsl:*[name()=name(current())][@match=current()/@match][1]" mode="refer-to"/>
    64        <br/>
    65       </xsl:if> 
    66      <xsl:if test="msxsl:node-set($stylesheet-tree)/stylesheet/stylesheet[@method='import']/descendant::xsl:*[name()=name(current())][@name=current()/@name][(@mode=current()/@mode) or (not(@mode) and not(current()/@mode))]">
    67         Overriding identical name: <xsl:apply-templates select="msxsl:node-set($stylesheet-tree)/stylesheet/stylesheet[@method='import']/descendant::xsl:*[name()=name(current())][@name=current()/@name][1]" mode="refer-to"/>
    68        <br/>
    69       </xsl:if> 
    70       <xsl:variable name="comments-before-this-element" select="preceding-sibling::comment()"/>
    71       <xsl:variable name="previous-element-id">
    72         <xsl:choose>
    73           <xsl:when test="preceding-sibling::*">
    74             <xsl:value-of select="generate-id(preceding-sibling::*[1])"/>
    75           </xsl:when>
    76           <xsl:otherwise>
    77             <xsl:value-of select="generate-id(parent::*)"/>
    78           </xsl:otherwise>
    79         </xsl:choose>
    80       </xsl:variable>
    81       <xsl:variable name="comments-before-previous-element" select="/descendant::*[generate-id() = $previous-element-id]/preceding-sibling::comment()"/>
    82       <xsl:variable name="comments-between" select="$comments-before-this-element[count(.|$comments-before-previous-element) != count($comments-before-previous-element)] "/>
    83       <xsl:for-each select="msxsl:node-set($comments-between)">
    84         <xsl:value-of select="self::comment()" disable-output-escaping="yes"/><br/>
    85       </xsl:for-each>
    86  
    87       <a>
    88        <xsl:attribute name="href">javascript:toggleElm('code<xsl:value-of select="generate-id()"/>')</xsl:attribute>
    89        View code
    90       </a>
    91       <PRE STYLE="border-style:solid;display:none;">
    92         <xsl:attribute name="id">code<xsl:value-of select="generate-id()"/></xsl:attribute>
    93         <xsl:apply-templates select="self::*" mode="code-output" />
    94       </PRE>
    95  
    96       <hr/>
    97    </xsl:template>
    98    
    99    <xsl:template match="/" mode="tree-building">
   100      <xsl:param name="included-from"/>
   101      <xsl:apply-templates select="descendant::xsl:template|descendant::xsl:variable|descendant::xsl:param" mode="tree-building">
   102        <xsl:with-param name="included-from" select="$included-from"/>
   103      </xsl:apply-templates>
   104       <xsl:for-each select="descendant::xsl:import">
   105         <stylesheet method="import">
   106           <xsl:attribute name="href"><xsl:value-of  select="@href"/></xsl:attribute>
   107           <xsl:apply-templates select="document(@href)" mode="tree-building"/>
   108         </stylesheet>
   109       </xsl:for-each>
   110       <xsl:for-each select="descendant::xsl:include">
   111         <stylesheet method="include"><xsl:attribute name="href"><xsl:value-of  select="@href"/></xsl:attribute></stylesheet>
   112         <xsl:attribute name="href"><xsl:value-of  select="@href"/></xsl:attribute>
   113         <xsl:apply-templates select="document(@href)" mode="tree-building">
   114           <xsl:with-param name="included-from" select="@href"/>
   115         </xsl:apply-templates>
   116       </xsl:for-each>
   117    </xsl:template>
   118    
   119    <xsl:template match="xsl:template|xsl:variable|xsl:param|@mode|@match|@name" mode="tree-building" >
   120      <xsl:param name="included-from"/>
   121      <xsl:copy>
   122        <xsl:if test="$included-from"><xsl:attribute name="included-from" ><xsl:value-of select="$included-from"/></xsl:attribute></xsl:if>
   123        <xsl:apply-templates select="@mode|@match|@name" mode="tree-building"/>
   124      </xsl:copy>
   125    
   126    </xsl:template>
   127  
   128    <xsl:template match="xsl:template|xsl:variable|xsl:param" mode="refer-to" >
   129  
   130       <xsl:call-template name="link-to-stylesheet">
   131         <xsl:with-param name="linking-text">
   132          <xsl:call-template name="display-xsl-element-inline"/>
   133          in <xsl:value-of select="parent::stylesheet/@href"/>
   134         </xsl:with-param>
   135       </xsl:call-template>
   136    </xsl:template>
   137  
   138    <xsl:template name="display-xsl-element">
   139      <xsl:param name="elm"/>
   140       &lt;
   141       <span class="xsl-elm"><xsl:value-of select="name($elm)"/></span><br/>
   142       <xsl:for-each select="@*">
   143         <span style="margin-left:20"><xsl:call-template name="display-attribute"></xsl:call-template><br/></span>
   144       </xsl:for-each>
   145  
   146       &gt;<br/>
   147      <xsl:for-each select="xsl:param">
   148      Parameter: <xsl:call-template name="display-xsl-element-inline"/><br/>
   149      </xsl:for-each>
   150       
   151    </xsl:template>
   152    
   153    <xsl:template name="display-xsl-element-inline">
   154      <xsl:param name="elm" select="current()"/>
   155       &lt;<span class="xsl-elm"><xsl:value-of select="name(msxsl:node-set($elm))"/></span>
   156       <xsl:for-each select="@*">
   157         <xsl:text> </xsl:text>
   158         <xsl:call-template name="display-attribute"></xsl:call-template>
   159       </xsl:for-each>
   160  
   161       &gt;
   162       
   163    </xsl:template>
   164    <xsl:template name="display-attribute">
   165      <xsl:param name="attr" select="current()"/>
   166       <span class="xsl-attr-name"><xsl:value-of select="name(msxsl:node-set($attr))"/></span> <xsl:text>=</xsl:text>
   167  
   168       <span class="xsl-attr-value"><xsl:value-of select="msxsl:node-set($attr)"/></span> 
   169    </xsl:template>
   170  
   171    <xsl:template name="display-stylesheet-tree">
   172      <xsl:value-of select="$document-name"/><br/>
   173      <xsl:for-each select="msxsl:node-set($stylesheet-tree)/stylesheet/descendant::stylesheet">
   174        <span style="margin-left:{20*(count(ancestor::*)+1)}">
   175        <xsl:value-of select="@method"/>: 
   176        <xsl:call-template name="link-to-stylesheet"/>
   177        </span><br/>
   178      </xsl:for-each>
   179    </xsl:template>
   180  
   181    <xsl:template name="filename-for-stylesheet-name">
   182      <xsl:param name="stylesheet-name"></xsl:param>
   183      <xsl:value-of select="translate($stylesheet-name, './\', '___')"/>
   184      <xsl:text>.htm</xsl:text>
   185    </xsl:template>
   186  
   187  
   188    <xsl:template name="link-to-stylesheet">
   189      <xsl:param name="node" select="current()"/>
   190      <xsl:param name="linking-text" />
   191      <xsl:variable name="local-linking-text">
   192        <xsl:choose>
   193        <xsl:when test="$linking-text"><xsl:copy-of select="$linking-text"/></xsl:when>
   194         <xsl:otherwise><xsl:value-of select="$node/ancestor-or-self::stylesheet[1]/@href"/></xsl:otherwise>
   195        </xsl:choose>
   196      </xsl:variable>
   197      <a>
   198      <xsl:attribute name="href">
   199      <xsl:call-template name="filename-for-stylesheet-name"><xsl:with-param name="stylesheet-name" select="$node/ancestor-or-self::stylesheet[1]/@href"/>
   200      </xsl:call-template>
   201       <xsl:if test="not(local-name($node) = 'stylesheet')">
   202         <xsl:text>#elmxsl_</xsl:text><xsl:value-of select="translate(local-name($node), ':.', '__')"/>|<xsl:value-of select="$node/@name"/>|<xsl:value-of select="$node/@match"/>
   203       </xsl:if>
   204      </xsl:attribute>
   205       <xsl:copy-of select="$local-linking-text"/>
   206      </a>
   207    </xsl:template>
   208  
   209  
   210      
   211    <xsl:template match="text()" priority="1" mode="code-output">
   212      <xsl:value-of select="self::text()" />
   213    </xsl:template>
   214  
   215    <xsl:template match="*" mode="code-output">
   216      <xsl:text>&lt;</xsl:text>
   217      <xsl:apply-templates select="current()" mode="show-name"/>
   218      <xsl:apply-templates select="@*" mode="code-output"/>
   219      <xsl:text>&gt;</xsl:text>
   220      <xsl:apply-templates select="node()" mode="code-output"/>
   221      <xsl:text>&lt;/</xsl:text>
   222      <xsl:apply-templates select="current()" mode="show-name"/>
   223      <xsl:text>&gt;</xsl:text>
   224    </xsl:template>
   225  
   226    <xsl:template match="@*" mode="code-output">
   227      <xsl:text> </xsl:text>
   228      <xsl:value-of select="name()"/>
   229      <xsl:text>=&quot;</xsl:text><xsl:value-of select="current()"/><xsl:text>&quot;</xsl:text>
   230    </xsl:template>
   231  
   232    <xsl:template match="xsl:*/@*" mode="code-output">
   233      <xsl:text> </xsl:text>
   234      <span class="xsl-attr-name">
   235        <xsl:value-of select="name()"/>
   236      </span>
   237      <span class="xsl-attr-value">
   238        <xsl:text>=&quot;</xsl:text><xsl:value-of select="current()"/><xsl:text>&quot;</xsl:text>
   239      </span>
   240    </xsl:template>
   241  
   242    <xsl:template match="xsl:call-template/@name" mode="code-output">
   243      <xsl:text> </xsl:text>
   244      <xsl:value-of select="name()"/>
   245      <xsl:text>=&quot;</xsl:text>
   246      <xsl:call-template name="link-to-stylesheet">
   247      <xsl:with-param name="node" select="msxsl:node-set($stylesheet-tree)/descendant::xsl:template[@name=current()][1]"/>
   248      <xsl:with-param name="linking-text" select="string(current())"/>
   249      </xsl:call-template>
   250      <xsl:text>&quot;</xsl:text>
   251    </xsl:template>
   252  
   253    <xsl:template match="comment()" mode="code-output">
   254      <span class="xsl-comment">
   255      <xsl:text><![CDATA[<!--]]></xsl:text>
   256      <xsl:value-of select="current()"/>
   257      <xsl:text><![CDATA[-->]]></xsl:text>
   258      </span>
   259    </xsl:template>
   260  
   261    <xsl:template match="*" mode="show-name">
   262      <xsl:value-of select="name()"/>
   263    </xsl:template>
   264  
   265    <xsl:template match="xsl:*" mode="show-name">
   266      <a class="xsl-elm" target="_blank">
   267        <xsl:attribute name="href">http://www.vbxml.com/xsl/elmxsl_<xsl:value-of select="translate(local-name(), ':.', '__')"/>.asp</xsl:attribute>
   268      <xsl:value-of select="name()"/>
   269      </a>
   270    </xsl:template>
   271  
   272  
   273  
   274  </xsl:stylesheet>