[Commits] (jeffrey) Started using EXSLT, added lots of functions.

commits at osafoundation.org commits at osafoundation.org
Fri Jan 23 21:48:37 PST 2004


Commit by: jeffrey
Modified files:
osaf/chandler/Chandler/distrib/transforms/includes/helperFunctions.xsl 1.3 1.4

Log message:
Started using EXSLT, added lots of functions.


ViewCVS links:
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/distrib/transforms/includes/helperFunctions.xsl.diff?r1=text&tr1=1.3&r2=text&tr2=1.4

Index: osaf/chandler/Chandler/distrib/transforms/includes/helperFunctions.xsl
diff -u osaf/chandler/Chandler/distrib/transforms/includes/helperFunctions.xsl:1.3 osaf/chandler/Chandler/distrib/transforms/includes/helperFunctions.xsl:1.4
--- osaf/chandler/Chandler/distrib/transforms/includes/helperFunctions.xsl:1.3	Wed Nov 26 16:14:34 2003
+++ osaf/chandler/Chandler/distrib/transforms/includes/helperFunctions.xsl	Fri Jan 23 21:48:05 2004
@@ -1,8 +1,11 @@
 <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-     xmlns:core="//Schema/Core">
+     xmlns:core="//Schema/Core"
+     xmlns:exsl="http://exslt.org/common"
+     xmlns:func="http://exslt.org/functions"
+     extension-element-prefixes="exsl func">
 
-   <xsl:variable name = "root" select = "/" />     
+   <xsl:variable name = "root" select = "/" />
 
 <!-- 
      createRelativePath creates a relative path from two absolute (UNIX style) paths.
@@ -56,7 +59,7 @@
 		<xsl:choose>
            <xsl:when test = "$src=''">
               <xsl:value-of select="$target" />
-                 <xsl:if test = "substring($target, string-length($target)!='/')">
+                 <xsl:if test = "substring($target, string-length($target))!='/'">
               <xsl:text>/</xsl:text>
               </xsl:if>
            </xsl:when>           
@@ -103,7 +106,7 @@
 -->
    <xsl:template match="@itemref" mode="quickRelpath">
       <xsl:call-template name="createRelativePath">
-         <xsl:with-param name="src" select="/core:Parcel/@describes" />
+         <xsl:with-param name="src" select="$root/core:Parcel/@describes" />
 
          <xsl:with-param name="target">
             <xsl:apply-templates mode="getURIFromQName" select="." />
@@ -111,19 +114,32 @@
       </xsl:call-template>
    </xsl:template>
    
-<!-- Remove text up to and including a ':' character to get the local name
-     of the object being referred to.
+<!-- Remove text up to and including a ':', remove everything after a '/' 
+     to get the name of the Kind being referred to.
 -->
-   <xsl:template match="@itemref" mode="quickRef">
+<xsl:template match="@itemref" mode="quickRef">
+   <xsl:variable name="full">
       <xsl:choose>
          <xsl:when test="substring-after(., ':')=''">
-            <xsl:value-of select="." />   
-   	     </xsl:when>
-   	     <xsl:otherwise>
-            <xsl:value-of select="substring-after(., ':')" />   	 
-   	     </xsl:otherwise>
+            <xsl:value-of select="." />
+         </xsl:when>
+
+         <xsl:otherwise>
+            <xsl:value-of select="substring-after(., ':')" />
+         </xsl:otherwise>
       </xsl:choose>
-   </xsl:template>	
+   </xsl:variable>
+
+   <xsl:choose>
+      <xsl:when test="substring-before($full, '/')">
+         <xsl:value-of select="substring-before($full, '/')" />
+      </xsl:when>
+
+      <xsl:otherwise>
+         <xsl:value-of select="$full" />
+      </xsl:otherwise>
+   </xsl:choose>
+</xsl:template>
 
 <!-- Get the content of the referenced item's child -->
    <xsl:template match="@itemref" mode="derefChild">
@@ -139,7 +155,7 @@
             <xsl:value-of select="/core:Parcel/*[@itemName=$ref]/*[local-name()=$child]"/>
          </xsl:when>
          <xsl:otherwise>
-            <xsl:variable name="otherdoc" select="document(concat($relpath, $constants.parcelFileName), /)" />
+            <xsl:variable name="otherdoc" select="document(concat($relpath, $constants.parcelFileName), $root)" />
             <xsl:value-of select="$otherdoc/core:Parcel/*[@itemName=$ref]/*[local-name()=$child]"/>
          </xsl:otherwise>
       </xsl:choose>
@@ -160,6 +176,28 @@
       </xsl:if>
    </xsl:template>
 
+<!-- Dereference the given itemref, look at the child matching the child paramater,
+     dereference that itemref, then return the resulting item's displayName-->
+   <xsl:template match="@itemref" mode="doubleDerefDisplayName">
+      <xsl:param name="child"/>
+      <xsl:variable name="ref">
+         <xsl:apply-templates select="." mode="quickRef" />
+      </xsl:variable>
+      <xsl:variable name="relpath">
+         <xsl:apply-templates select="." mode="quickRelpath" />
+      </xsl:variable>
+      <xsl:choose>
+         <xsl:when test="$relpath=''">
+            <xsl:apply-templates select="/core:Parcel/*[@itemName=$ref]/*[local-name()=$child]/@itemref" mode="derefDisplayName"/>
+         </xsl:when>
+         <xsl:otherwise>
+            <xsl:variable name="otherdoc" select="document(concat($relpath, $constants.parcelFileName), $root)" />
+            <xsl:apply-templates select="$otherdoc/core:Parcel/*[@itemName=$ref]/*[local-name()=$child]/@itemref" mode="derefDisplayName"/>
+         </xsl:otherwise>
+      </xsl:choose>
+   </xsl:template>
+
+
 <!-- getDisplayName defaults to using the itemName if no
      displayName exists, as is the case for many items in Core.
 -->
@@ -174,32 +212,41 @@
       </xsl:choose>
    </xsl:template>
 
-<!-- Return the name that hrefs should link to.  Names for Attributes and Kinds
-     should just be the itemName,unless the attribute is a local attribute, in
-     which case it should be named (parent itemName)_(itemName)
--->
-   <xsl:template match="*" mode="getHrefName">
-      <xsl:if test = "local-name(..)='Kind'">
-      <xsl:value-of select="../@itemName"/>
-         <xsl:text>_</xsl:text>
-      </xsl:if>
-      <xsl:value-of select="@itemName"/>
+<!-- Get the file type.  This is the pluralized local name + .html.-->
+   <xsl:template match="*" mode="getFilename">
+      <xsl:value-of select="func:pluralize(local-name(.))"/>
+      <xsl:text>.html</xsl:text>	
    </xsl:template>
-
-<!-- Get the file type.  This is the local name + s.html, unless this is a 
-     local attribute, in which case return Kinds.html.
+   
+<!-- Return the plural of the given word.  Currently just deals with returning Aliases instead
+     of Aliass.
 -->
-   <xsl:template match="*" mode="getFilename">
+<func:function name="func:pluralize">
+   <xsl:param name="name" />
+   <xsl:choose>
+      <xsl:when test="$name='Alias'">
+         <func:result select="'Aliases'"/>
+      </xsl:when>
+      <xsl:otherwise>
+         <func:result select="concat($name,'s')"/>	
+      </xsl:otherwise>
+   </xsl:choose>    
+</func:function>
+
+
+   <xsl:template name="pluralize">
+      <xsl:param name="name" />
       <xsl:choose>
-      	<xsl:when test="local-name(..)='Kind'">
-      	   <xsl:value-of select="'Kinds.html'"/>
+      	<xsl:when test="$name='Alias'">
+      	   <xsl:value-of select="'Aliases'"/>
       	</xsl:when>
       	<xsl:otherwise>
-      	   <xsl:value-of select="concat(local-name(.),'s.html')"/>
+      	   <xsl:value-of select="concat($name,'s')"/>	
       	</xsl:otherwise>
-      </xsl:choose>
+      </xsl:choose>      
    </xsl:template>
 
+
 <!-- create an anchor linking to the given item -->
    <xsl:template match="*" mode="getHrefAnchor">
       <xsl:param name="text" />
@@ -245,13 +292,15 @@
    <xsl:template match="*" mode="getNameAnchor">
       <a>
          <xsl:attribute name="name">
-            <xsl:apply-templates select="." mode="getHrefName" />
+            <xsl:value-of select="@itemName" />
          </xsl:attribute>
          <xsl:apply-templates select="." mode="getDisplayName"/>
       </a>
    </xsl:template>
 
-<!-- Dereference the given itemref and create an href to the resulting item-->
+<!-- Dereference the given item reference (not the itemref attribute itself)
+     and create an href to the resulting item
+-->
    <xsl:template match="*" mode="derefHref">
       <xsl:param name="text" />
       <xsl:variable name="ref">
@@ -267,7 +316,7 @@
             </xsl:apply-templates>
          </xsl:when>
          <xsl:otherwise>
-            <xsl:variable name="otherdoc" select="document(concat($relpath, $constants.parcelFileName), /)" />
+            <xsl:variable name="otherdoc" select="document(concat($relpath, $constants.parcelFileName), $root)" />
             <xsl:apply-templates select="$otherdoc/core:Parcel/*[@itemName=$ref]" mode="getHrefAnchor">
                <xsl:with-param name="text" select="$text" />
             </xsl:apply-templates>
@@ -275,17 +324,7 @@
       </xsl:choose>
    </xsl:template>
 
-<!-- Dereference the given item's child matching the child paramater
-     and create an href to the resulting item-->
-   <xsl:template match="*" mode="derefChildHref">
-      <xsl:param name="child"/>
-      <xsl:apply-templates select="./*[local-name()=$child]" mode="derefHref" />
-   </xsl:template>
-
-<!-- Dereference the given itemref, look at the child matching the child paramater,
-     dereference that itemref, then create an href to the resulting item-->
-   <xsl:template match="@itemref" mode="doubleDerefHref">
-      <xsl:param name="child"/>
+   <xsl:template match="@itemref" mode="getTypeSchema">
       <xsl:variable name="ref">
          <xsl:apply-templates select="." mode="quickRef" />
       </xsl:variable>
@@ -294,17 +333,185 @@
       </xsl:variable>
       <xsl:choose>
          <xsl:when test="$relpath=''">
-            <xsl:apply-templates select="/core:Parcel/*[@itemName=$ref]" mode="derefChildHref">
-               <xsl:with-param name="child" select="$child"/>
-            </xsl:apply-templates>
+            <xsl:apply-templates select="/core:Parcel/*[@itemName=$ref]/core:type/@itemref" mode="getSchema"/>
          </xsl:when>
          <xsl:otherwise>
-            <xsl:variable name="otherdoc" select="document(concat($relpath, $constants.parcelFileName), /)" />
-            <xsl:apply-templates select="$otherdoc/core:Parcel/*[@itemName=$ref]" mode="derefChildHref">
-               <xsl:with-param name="child" select="$child"/>
-            </xsl:apply-templates>
+            <xsl:variable name="otherdoc" select="document(concat($relpath, $constants.parcelFileName), $root)" />
+            <xsl:apply-templates select="$otherdoc/core:Parcel/*[@itemName=$ref]/core:type/@itemref" mode="getSchema"/>
          </xsl:otherwise>
       </xsl:choose>
    </xsl:template>
+   
+   <xsl:template match="@itemref" mode="getSchema">
+      <xsl:variable name="relpath">
+         <xsl:apply-templates select="." mode="quickRelpath" />
+      </xsl:variable>
+      <xsl:choose>
+         <xsl:when test="$relpath=''">
+            <xsl:apply-templates select="/core:Parcel" mode="getDisplayName"/>
+         </xsl:when>
+         <xsl:otherwise>
+            <xsl:variable name="otherdoc" select="document(concat($relpath, $constants.parcelFileName), $root)" />
+            <xsl:apply-templates select="$otherdoc/core:Parcel" mode="getDisplayName"/>
+         </xsl:otherwise>
+      </xsl:choose>
+      <xsl:value-of select="./core:Parcel/core:displayName"/>
+   </xsl:template>   
+
+<!-- Remove text up to and including a ':', remove everything after a '/' 
+     to get the name of the Kind being referred to.
+-->
+<func:function name="func:refPrimary">
+   <xsl:param name="ref" />
+   <xsl:variable name="full">
+      <xsl:choose>
+         <xsl:when test="substring-after($ref, ':')=''">
+            <xsl:value-of select="$ref" />
+         </xsl:when>
+
+         <xsl:otherwise>
+            <xsl:value-of select="substring-after($ref, ':')" />
+         </xsl:otherwise>
+      </xsl:choose>
+   </xsl:variable>
+
+   <xsl:choose>
+      <xsl:when test="substring-before($full, '/')">
+         <func:result select="substring-before($full, '/')" />
+      </xsl:when>
+
+      <xsl:otherwise>
+         <func:result select="$full" />
+      </xsl:otherwise>
+   </xsl:choose>
+</func:function>
+
+<!-- Remove everything before a '/' to get the name of the Local Attribute being referred to. -->
+<func:function name="func:refLocalAttribute">
+   <xsl:param name="ref" />
+   <func:result select="substring-after($ref, '/')" />
+</func:function>
+
+
+<func:function name="func:deref">
+   <xsl:param name="itemrefAttribute" />
+
+   <xsl:variable name="kind" select="func:refPrimary($itemrefAttribute)"/>
+   <xsl:variable name="local" select="func:refLocalAttribute($itemrefAttribute)"/>
+
+   <xsl:variable name="relpath">
+      <xsl:apply-templates select="$itemrefAttribute" mode="quickRelpath" />
+   </xsl:variable>
+   
+   <xsl:variable name="otherdoc" select="document(concat($relpath, $constants.parcelFileName), $root)" />
+
+   <xsl:choose>
+      <xsl:when test="$local=''">
+         <func:result select="$otherdoc/core:Parcel/*[@itemName=$kind]" />
+      </xsl:when>
+
+      <xsl:otherwise>
+         <func:result select="$otherdoc/core:Parcel/*[@itemName=$kind]/core:Attribute[@itemName=$local]" />
+      </xsl:otherwise>
+   </xsl:choose>
+</func:function>
+
+<xsl:variable name = "test">
+<empty/>
+</xsl:variable>
+
+<func:function name="func:getAttributeValue">
+   <xsl:param name="context"/>
+   <xsl:param name="attribute"/>
+      <xsl:choose>
+      	<xsl:when test="$context/*[local-name()=$attribute]">
+      	   <xsl:choose>
+      	   	<xsl:when test="$context/*[local-name()=$attribute]/@itemref">
+      	   	   <func:result select="func:deref($context/*[local-name()=$attribute]/@itemref)" />
+      	   	</xsl:when>
+      	   	<xsl:otherwise>
+               <func:result select="$context/*[local-name()=$attribute]/text()" />
+      	   	</xsl:otherwise>
+      	   </xsl:choose>
+      	</xsl:when>
+      	<xsl:when test = "$context/core:attributes/@itemref[func:refLocalAttribute(.)=$attribute]">
+           <func:result select="func:getDefaultNode(func:deref($context/core:attributes/@itemref[func:refLocalAttribute(.)=$attribute]))" />
+      	</xsl:when>
+      	<xsl:when test = "$context/core:attributes/@itemref[func:refPrimary(.)=$attribute]">
+           <func:result select="func:getDefaultNode(func:deref($context/core:attributes/@itemref[func:refPrimary(.)=$attribute]))" />
+      	</xsl:when>
+
+      	<xsl:when test = "$context/core:superKinds">
+      	   <func:result select="func:getAttributeValue(func:deref($context/core:superKinds/@itemref),$attribute)" />
+      	</xsl:when>
+      	<xsl:when test = "func:hasSuperKind($context)">
+      	   <func:result select="func:getAttributeValue($coreDoc//core:Kind[@itemName='Item'],$attribute)" />
+      	</xsl:when>
+      	<xsl:otherwise>
+      	   <func:result select="exsl:node-set($test)"/>
+      	</xsl:otherwise>
+      </xsl:choose>
+</func:function>
+
+<func:function name="func:hasSuperKind">
+   <xsl:param name="context" />
+
+   <xsl:choose>
+      <xsl:when test="$context/@itemName='Item'">
+         <func:result select="false()" />
+      </xsl:when>
+
+      <xsl:otherwise>
+         <func:result select="true()" />
+      </xsl:otherwise>
+   </xsl:choose>
+</func:function>
+
+<func:function name="func:getDefaultNode">
+   <xsl:param name="context" />
+
+   <xsl:choose>
+      <xsl:when test="$context/core:defaultValue">
+         <func:result select="$context/core:defaultValue" />
+      </xsl:when>
+
+      <xsl:when test="$context/core:superAttribute">
+         <func:result select="func:getDefaultNode(func:deref($context/core:superAttribute/@itemref))" />
+      </xsl:when>
+   </xsl:choose>
+</func:function>
+
+<func:function name="func:getAspect">
+   <xsl:param name="context" />
+
+   <xsl:param name="attribute" />
+
+   <xsl:choose>
+      <xsl:when test="$context/*[local-name()=$attribute]">
+         <func:result select="$context/*[local-name()=$attribute]" />
+      </xsl:when>
+
+      <xsl:when test="$context/core:superAttribute">
+         <func:result select="func:getAspect(func:deref($context/core:superAttribute/@itemref), $attribute)" />
+      </xsl:when>
+
+      <xsl:otherwise>
+         <func:result select="func:getDefaultNode($coreDoc//core:Kind[@itemName='Attribute']/core:Attribute[@itemName=$attribute])" />
+      </xsl:otherwise>
+   </xsl:choose>
+</func:function>
+
+
+<!-- 
+
+does inverseAttribute want to point to otherName?
+
+* inherit from Items, not just Kinds (and others?)
+* deal with local attribute references, in addition to displaying local attributes, especially in getHrefAnchor etc.
+
+* display "is a subAttribute of" for subAttributes
+
+-->
+
    
 </xsl:stylesheet>



More information about the Commits mailing list