home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / simplify-sitemap.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  14.4 KB  |  359 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.   Copyright 1999-2004 The Apache Software Foundation
  4.  
  5.   Licensed under the Apache License, Version 2.0 (the "License");
  6.   you may not use this file except in compliance with the License.
  7.   You may obtain a copy of the License at
  8.  
  9.       http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.   Unless required by applicable law or agreed to in writing, software
  12.   distributed under the License is distributed on an "AS IS" BASIS,
  13.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.   See the License for the specific language governing permissions and
  15.   limitations under the License.
  16. -->
  17. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:map="http://apache.org/cocoon/sitemap/1.0">
  18.     
  19.     <xsl:output indent="yes"/>
  20.     
  21.     <xsl:variable name="globals" select="0"/>
  22.     <xsl:variable name="nomatch" select="'::::*****:::::'"/>
  23.     
  24.     <!--
  25.       ! skipping some 
  26.       ! -->
  27.     
  28.     <xsl:template match="map:components|map:views|map:view|map:component-configurations|map:parameter">
  29.     </xsl:template>
  30.     
  31.     
  32.     <xsl:template match="map:match" mode="print">
  33.         <xsl:param name="use_cnt" select="-1"/>
  34.         <xsl:param name="depth"  select="0"/>
  35.  
  36.         <match pattern="{@pattern}">
  37.             <xsl:if test="$use_cnt>0">
  38.                 <xsl:attribute name="used"><xsl:value-of select="$use_cnt"/></xsl:attribute>
  39.             </xsl:if>
  40.             <xsl:apply-templates>
  41.                 <xsl:with-param name="depth"  select="$depth+1"/>        
  42.             </xsl:apply-templates>
  43.         </match>
  44.     </xsl:template>
  45.     
  46.     
  47.     <xsl:template match="map:call" mode="children">
  48.         <xsl:param name="depth"  select="0"/>
  49.  
  50.         <xsl:apply-templates select="//map:resource[@name=current()/@resource]">
  51.             <xsl:with-param name="depth" select="$depth+1"/>
  52.         </xsl:apply-templates>
  53.         
  54.     </xsl:template>
  55.          
  56.          
  57.      <xsl:template match="map:redirect-to" mode="children">
  58.         <xsl:param name="depth"  select="0"/>
  59.  
  60.         <xsl:variable name="redirectname">
  61.             <xsl:call-template name="redirectpath">
  62.                 <xsl:with-param name="file" select="@uri"/>
  63.                 <xsl:with-param name="parentfile" select="../@pattern"/>
  64.             </xsl:call-template>
  65.         </xsl:variable>
  66.  
  67.         <xsl:attribute name="to-uri"><xsl:value-of select="$redirectname"/></xsl:attribute>
  68.         
  69.             <xsl:apply-templates mode="pipeline" select=".">
  70.                 <xsl:with-param name="depth" select="$depth+1"/>
  71.             </xsl:apply-templates>
  72.         
  73.     </xsl:template>
  74.  
  75.             
  76.     <xsl:template match="map:match" mode="pipeline">
  77.         <xsl:param name="depth"  select="0"/>
  78.  
  79.         <xsl:choose>
  80.             <xsl:when test="not($globals)">
  81.                 <xsl:apply-templates select="." mode="print">
  82.                             <xsl:with-param name="depth"  select="$depth+1"/>        
  83.                 </xsl:apply-templates>
  84.             </xsl:when>
  85.             
  86.             <xsl:otherwise>
  87.  
  88.  
  89.                     <xsl:apply-templates select="." mode="print">
  90.                         <xsl:with-param name="use_cnt" select="$cnt_direct+$cnt_indirect"/>
  91.                         <xsl:with-param name="depth"  select="$depth+1"/>        
  92.                     </xsl:apply-templates>
  93.             </xsl:otherwise>
  94.         </xsl:choose>
  95.     </xsl:template>
  96.  
  97.     
  98.     
  99.     <xsl:template match="map:redirect-to">
  100.         <xsl:param name="depth"  select="0"/>
  101.  
  102.         <xsl:variable name="redirectname">
  103.             <xsl:call-template name="redirectpath">
  104.                 <xsl:with-param name="file" select="@uri"/>
  105.                 <xsl:with-param name="parentfile" select="../@pattern"/>
  106.             </xsl:call-template>
  107.         </xsl:variable>
  108.         <redirect to="{@uri}" src="{@uri}">
  109.             <xsl:apply-templates mode="pipeline" select=".">
  110.                 <xsl:with-param name="depth"  select="$depth+1"/>        
  111.                 <xsl:with-param name="redirectname" select="$redirectname"/>
  112.             </xsl:apply-templates>
  113.         </redirect>
  114.     </xsl:template>
  115.     
  116.     
  117.     <xsl:template match="*" mode="pipeline">
  118.         <xsl:param name="redirectname"/>
  119.         <xsl:param name="depth"  select="0"/>
  120.         
  121.         <xsl:variable name="src">
  122.             <xsl:if test="not(contains(@src,'cocoon:/'))">cocoon:/</xsl:if>
  123.             <xsl:choose>
  124.                 <xsl:when test="$redirectname!=''">
  125.                     <xsl:value-of select="$redirectname"/>
  126.                 </xsl:when>
  127.                 <xsl:when test="contains(concat(@src,@uri),'?')">
  128.                     <xsl:value-of select="substring-before(concat(@src,@uri),'?')"/>
  129.                 </xsl:when>
  130.                 <xsl:otherwise>
  131.                     <xsl:value-of select="concat(@src,@uri)"/>
  132.                 </xsl:otherwise>
  133.             </xsl:choose>
  134.         </xsl:variable>
  135.         
  136.         <xsl:if test="$depth < 100">
  137.             <pipeline src="{concat(@src,@uri)}">
  138.                 <xsl:copy-of select="@element"/>
  139.                 <xsl:variable name="src0">
  140.                     <xsl:call-template name="skip-interparam-slashes">
  141.                         <xsl:with-param name="str" select="substring-after($src,'cocoon:/')"/>
  142.                     </xsl:call-template>
  143.                 </xsl:variable> 
  144.                 <xsl:variable name="thepattern">
  145.                     <xsl:call-template name="find-match">
  146.                         <xsl:with-param name="request" select="$src0"/>
  147.                     </xsl:call-template>
  148.                 </xsl:variable>
  149.                 <xsl:message>- found <xsl:value-of select="$thepattern"/></xsl:message>
  150.                 <xsl:choose>
  151.                     <xsl:when test="count(//map:match[@pattern=$thepattern])>0">
  152.                         <xsl:apply-templates select="//map:match[@pattern=$thepattern]" mode="pipeline">
  153.                             <xsl:with-param name="depth" select="$depth+1"/>
  154.                         </xsl:apply-templates>
  155.                     </xsl:when>
  156.  
  157.                     <xsl:otherwise>
  158.                         <xsl:call-template name="find-match">
  159.                             <xsl:with-param name="request" select="$src0"/>
  160.                         </xsl:call-template>
  161.                         <LEGEPIPELINE src="{$src}">
  162.                             <pattern>
  163.                                 <xsl:copy-of select="$thepattern"/>
  164.                             </pattern>
  165.                             <match ref="{substring-after($src,'cocoon:/')}" pattern="{concat(substring-before(substring-after($src,'cocoon:/'),'{'),substring-after($src,'}'))}"/>
  166.                         </LEGEPIPELINE>
  167.                     </xsl:otherwise>
  168.                 </xsl:choose>
  169.  
  170.             </pipeline>
  171.         </xsl:if>
  172.     </xsl:template>
  173.     
  174.     <!--xsl:template match="map:*" mode="pipeline">
  175.         <xsl:param name="depth"  select="0"/>
  176.  
  177.         <xsl:element name="{substring-after(name(),'map:')}">
  178.             <xsl:copy-of select="@*"/>
  179.  
  180.             <xsl:apply-templates select="." mode="children">
  181.                 <xsl:with-param name="depth"  select="$depth"/>        
  182.             </xsl:apply-templates>
  183.             
  184.         </xsl:element>
  185.         
  186.     </xsl:template-->
  187.  
  188.     
  189.     <xsl:template name="redirectpath">
  190.         <xsl:param name="file" select="@uri"/>
  191.         <xsl:param name="parentfile" select="../@pattern"/>
  192.         <xsl:choose>
  193.             <xsl:when test="contains($parentfile,'/')">
  194.                 <xsl:variable name="first-part" select="substring-before($parentfile,'/')"/>
  195.                 <xsl:variable name="rest-part">
  196.                     <xsl:call-template name="redirectpath">
  197.                         <xsl:with-param name="file" select="$file"/>
  198.                         <xsl:with-param name="parentfile" select="substring-after($parentfile,'/')"/>
  199.                     </xsl:call-template>
  200.                 </xsl:variable>
  201.                 <xsl:value-of select="concat($first-part,'/',$rest-part)"/>
  202.             </xsl:when>
  203.             <xsl:otherwise>
  204.                 <xsl:value-of select="$file"/>
  205.             </xsl:otherwise>
  206.         </xsl:choose>
  207.     </xsl:template>
  208.     
  209.     
  210.     
  211.     <xsl:template name="find-match">
  212.         <xsl:param name="request"/>
  213.         <xsl:message>find-match for <xsl:value-of select="$request"/></xsl:message>
  214.         <xsl:choose>
  215.             <xsl:when test="//map:match[@pattern=$request]">
  216.                 <xsl:value-of select="//map:match[@pattern=$request]/@pattern"/>
  217.             </xsl:when>
  218.             <xsl:otherwise>
  219.                 <xsl:call-template name="find-a-match">
  220.                     <xsl:with-param name="request" select="concat('',$request)"/>
  221.                     <xsl:with-param name="matches" select="//map:match[contains(@pattern,'*')]"/>
  222.                 </xsl:call-template>
  223.             </xsl:otherwise>
  224.         </xsl:choose>
  225.     </xsl:template>
  226.     
  227.     
  228.     <xsl:template name="find-a-match">
  229.         <xsl:param name="request"/>
  230.         <xsl:param name="matches"/>
  231.         <xsl:choose>
  232.             <xsl:when test="count($matches)=0">
  233.                 <xsl:value-of select="$nomatch"/>
  234.             </xsl:when>
  235.             <xsl:otherwise>
  236.                 <xsl:variable name="first-test-result">
  237.                     <xsl:call-template name="test-match">
  238.                         <xsl:with-param name="pattern" select="concat('',$matches[1]/@pattern)"/>
  239.                         <xsl:with-param name="request" select="$request"/>
  240.                     </xsl:call-template>
  241.                 </xsl:variable>
  242.                 <xsl:choose>
  243.                     <xsl:when test="$first-test-result=1">
  244.                         <xsl:value-of select="$matches[1]/@pattern"/>
  245.                     </xsl:when>
  246.                     <xsl:otherwise>
  247.                         <xsl:call-template name="find-a-match">
  248.                             <xsl:with-param name="request" select="$request"/>
  249.                             <xsl:with-param name="matches" select="$matches[position()>1]"/>
  250.                         </xsl:call-template>
  251.                     </xsl:otherwise>
  252.                 </xsl:choose>
  253.             </xsl:otherwise>
  254.         </xsl:choose>
  255.     </xsl:template>
  256.  
  257.  
  258.     <xsl:template name="test-match">
  259.         <xsl:param name="pattern"/>
  260.         <xsl:param name="request"/>
  261.  
  262.         <xsl:choose>
  263.             <xsl:when test="$pattern=$request">1</xsl:when>
  264.             <xsl:when test="not(contains($pattern,'*'))">0</xsl:when>
  265.             <xsl:when test="$request=''">0</xsl:when>
  266.             <xsl:when test="substring($pattern,1,1)='*'">
  267.  
  268.                 <xsl:variable name="subtext">
  269.                     <xsl:choose>
  270.                         <xsl:when test="substring($pattern,1,2)='**' and contains(substring($pattern,3),'*')">
  271.                             <xsl:value-of select="substring-before(substring($pattern,3),'*')"/>
  272.                         </xsl:when>
  273.                         <xsl:when test="substring($pattern,1,2)='**' ">
  274.                             <xsl:value-of select="substring($pattern,3)"/>
  275.                         </xsl:when>
  276.                         <xsl:when test="contains(substring($pattern,2),'*')">
  277.                             <xsl:value-of select="substring-before(substring($pattern,2),'*')"/>
  278.                         </xsl:when>
  279.                         <xsl:otherwise>
  280.                             <xsl:value-of select="substring($pattern,2)"/>
  281.                         </xsl:otherwise>
  282.                     </xsl:choose>
  283.                 </xsl:variable>
  284.  
  285.                 <xsl:choose>
  286.                     <xsl:when test="$subtext=''">
  287.                         <xsl:value-of select="number(substring($pattern,2,2)='*' or not(contains($request,'/')))"/>
  288.                     </xsl:when>
  289.                     <xsl:when test="not(contains($request,$subtext))">0</xsl:when>
  290.                     <xsl:when test="not(substring($pattern,2,1)='*') and contains(substring-before($request,$subtext),'/')">0</xsl:when>
  291.                     <xsl:otherwise>
  292.                         <xsl:call-template name="test-match-anybefore">
  293.                             <xsl:with-param name="pattern" select="substring-after($pattern,$subtext)"/>
  294.                             <xsl:with-param name="request" select="substring-after($request,$subtext)"/>
  295.                         </xsl:call-template>
  296.                     </xsl:otherwise>
  297.                 </xsl:choose>
  298.             </xsl:when>
  299.  
  300.             <xsl:when test="substring($pattern,1,1)=substring($request,1,1)">
  301.                 <xsl:call-template name="test-match">
  302.                     <xsl:with-param name="pattern" select="substring($pattern,2)"/>
  303.                     <xsl:with-param name="request" select="substring($request,2)"/>
  304.                 </xsl:call-template>
  305.             </xsl:when>
  306.             <xsl:otherwise>
  307.                 0                
  308.             </xsl:otherwise>
  309.         </xsl:choose>
  310.     </xsl:template>
  311.     
  312.     
  313.     <xsl:template name="test-match-anybefore">
  314.         <xsl:param name="pattern"/>
  315.         <xsl:param name="request"/>
  316.         <xsl:variable name="isok">
  317.             <xsl:call-template name="test-match">
  318.                 <xsl:with-param name="pattern" select="$pattern"/>
  319.                 <xsl:with-param name="request" select="$request"/>
  320.             </xsl:call-template>
  321.         </xsl:variable>
  322.         <xsl:choose>
  323.             <xsl:when test="$isok=1">1</xsl:when>
  324.             <xsl:when test="string-length($request)=0">
  325.                 <xsl:choose>
  326.                     <xsl:when test="$pattern=''">1</xsl:when>
  327.                     <xsl:otherwise>0</xsl:otherwise>
  328.                 </xsl:choose>
  329.             </xsl:when>
  330.             <xsl:otherwise>
  331.                 <xsl:call-template name="test-match-anybefore">
  332.                     <xsl:with-param name="pattern" select="$pattern"/>
  333.                     <xsl:with-param name="request" select="substring($request,2)"/>
  334.                 </xsl:call-template>
  335.             </xsl:otherwise>
  336.         </xsl:choose>
  337.     </xsl:template>
  338.  
  339.  
  340.     <xsl:template name="skip-interparam-slashes">
  341.         <xsl:param name="str"/>
  342.  
  343.         <xsl:choose>
  344.             <xsl:when test="contains(substring-after($str,'{'),'/')">
  345.                 <xsl:value-of select="concat(substring-before($str,'{'),'{',translate(substring-before(substring-after($str,'{'),'}'),'/','|'),'}')"/>
  346.                 <xsl:call-template name="skip-interparam-slashes">
  347.                     <xsl:with-param name="str" select="substring-after($str,'}')"/>
  348.                 </xsl:call-template>
  349.             </xsl:when>
  350.             <xsl:otherwise>
  351.                 <xsl:value-of select="$str"/>
  352.             </xsl:otherwise>
  353.         </xsl:choose>
  354.         
  355.     </xsl:template>
  356.  
  357.  
  358. </xsl:stylesheet>
  359.