[Gd-chatter] r11187 - trunk/libraries/xsd-generator

hannes at gwydiondylan.org hannes at gwydiondylan.org
Sun Feb 18 14:31:10 CET 2007


Author: hannes
Date: Sun Feb 18 14:31:09 2007
New Revision: 11187

Added:
   trunk/libraries/xsd-generator/xsd-to-dylan-xmpp.xml   (contents, props changed)
Log:
Job: minor
xslt to transform xsd to the form xsd-generator can parse.
this was done by turbo, I forgot this file in the last commit

Added: trunk/libraries/xsd-generator/xsd-to-dylan-xmpp.xml
==============================================================================
--- (empty file)
+++ trunk/libraries/xsd-generator/xsd-to-dylan-xmpp.xml	Sun Feb 18 14:31:09 2007
@@ -0,0 +1,197 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0" 
+  xmlns:xs="http://www.w3.org/2001/XMLSchema"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:output method="text"/>
+
+  <xsl:template match="/xs:schema">
+    <xsl:apply-templates select="xs:element | xs:complexType | //xs:documentation">
+      <xsl:with-param name="stanza" select="true()"/>
+    </xsl:apply-templates>
+  </xsl:template>
+
+  <xsl:template match="xs:documentation">
+    /*
+      <xsl:apply-templates/>
+    */
+  </xsl:template>
+
+  <xsl:template match="xs:element">
+    <xsl:param name="stanza"/>
+    <xsl:param name="element"/>
+    <xsl:choose>
+      <xsl:when test="$stanza">
+        define <xsl:if test="count(current()//xs:element) = 0">wrapped </xsl:if>stanza <xsl:choose>
+          <xsl:when test="contains(/xs:schema/@targetNamespace, 'http://')">
+            <xsl:call-template name="last-part">
+              <xsl:with-param name="string" select="translate(/xs:schema/@targetNamespace, '#', '-')"/>
+              <xsl:with-param name="separator" select="string('/')"/>
+            </xsl:call-template>
+          </xsl:when>
+          <xsl:otherwise>                      
+              <xsl:call-template name="last-part">
+                <xsl:with-param name="string" select="translate(/xs:schema/@targetNamespace, '#', '-')"/>
+              <xsl:with-param name="separator" select="string(':')"/>
+            </xsl:call-template>
+          </xsl:otherwise>
+        </xsl:choose><xsl:if test="$element"><xsl:value-of select="$element"/></xsl:if>-<xsl:value-of select="@name"/> ()
+          name "<xsl:value-of select="@name"/>";
+          namespace "<xsl:value-of select="/xs:schema/@targetNamespace"/>";
+          <xsl:choose><xsl:when test="@type">content :: <xsl:choose><xsl:when test="contains(@type, ':')">&lt;<xsl:call-template name="last-part">
+            <xsl:with-param name="string" select="translate(@type, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
+            <xsl:with-param name="separator" select="string(':')"/>
+            </xsl:call-template>&gt;</xsl:when>
+            <xsl:when test="/*/xs:simpleType[@name = current()/@type]"><xsl:call-template name="xs:simpleType">
+              <xsl:with-param name="node" select="/*/xs:simpleType[@name = current()/@type]"/>
+            </xsl:call-template></xsl:when>
+            <xsl:otherwise>&lt;string&gt;</xsl:otherwise></xsl:choose>;
+            </xsl:when>
+            <xsl:when test="xs:simpleType">content :: <xsl:call-template name="xs:simpleType">  
+              <xsl:with-param name="node" select="xs:simpleType"/>
+          </xsl:call-template>;</xsl:when>
+          </xsl:choose>
+          <xsl:if test="//xs:complexType[@name = current()/@type]">
+            <xsl:apply-templates select="//xs:complexType[@name = current()/@type]//xs:element">
+              <xsl:with-param name="stanza" select="false()"/>
+            </xsl:apply-templates>    
+            <!--
+              ^^^^^^^
+            param????
+            <xsl:call-template name="generate-name">
+                      <xsl:with-param name="nodes" select="ancestor::xs:element"/>
+                              </xsl:call-template>
+                              -->
+          </xsl:if>
+          <xsl:apply-templates select="xs:complexType">
+            <xsl:with-param name="stanza" select="false()"/>
+          </xsl:apply-templates>      
+        end;
+        <xsl:apply-templates select="current()//xs:element[@name]">
+          <xsl:with-param name="stanza" select="true()"/>
+          <xsl:with-param name="element" select="concat(string($element), '-', string(@name))" />
+        </xsl:apply-templates>
+      </xsl:when>
+      <xsl:otherwise>
+        element <xsl:call-template name="last-part">
+          <xsl:with-param name="string" select="@ref | @name"/>
+          <xsl:with-param name="separator" select="string(':')"/>
+          </xsl:call-template> :: <xsl:if test="count(current()//xs:element) = 0">wrapped(</xsl:if>&lt;<xsl:choose>
+        <xsl:when test="contains(/xs:schema/@targetNamespace, 'http://')">
+          <xsl:call-template name="last-part">
+            <xsl:with-param name="string" select="translate(/xs:schema/@targetNamespace, '#', '-')"/>
+            <xsl:with-param name="separator" select="string('/')"/>
+          </xsl:call-template>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:call-template name="last-part">
+            <xsl:with-param name="string" select="translate(/xs:schema/@targetNamespace, '#', '-')"/>
+            <xsl:with-param name="separator" select="string(':')"/>
+          </xsl:call-template>
+        </xsl:otherwise>
+          </xsl:choose><xsl:if test="not(@ref)"><xsl:call-template name="generate-name">
+        <xsl:with-param name="nodes" select="ancestor::xs:element"/>
+        </xsl:call-template></xsl:if>-<xsl:value-of select="@ref | @name"/>&gt;<xsl:if test="count(current()//xs:element) = 0">, <xsl:choose>
+        <xsl:when test="contains(/*/xs:element[@name = current()/@ref]/@type, ':')">&lt;<xsl:call-template name="last-part">
+            <xsl:with-param name="string" select="translate(/*/xs:element[@name = current()/@ref]/@type, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
+            <xsl:with-param name="separator" select="string(':')"/>
+            </xsl:call-template>&gt;</xsl:when>
+            <xsl:when test="/*/xs:simpleType[@name = /*/xs:element[@name = current()/@ref]/@type]"><xsl:call-template name="xs:simpleType">
+              <xsl:with-param name="node" select="/*/xs:simpleType[@name = /*/xs:element[@name = current()/@ref]/@type]"/>
+            </xsl:call-template></xsl:when>
+            <xsl:when test="/*/xs:element[@name = current()/@ref]/xs:simpleType"><xsl:call-template name="xs:simpleType">
+              <xsl:with-param name="node" select="/*/xs:element[@name = current()/@ref]/xs:simpleType"/>
+          </xsl:call-template></xsl:when>
+          <xsl:otherwise>&lt;string&gt;</xsl:otherwise>
+
+          
+    </xsl:choose>)</xsl:if><xsl:if test="@minOccurs">, min-occurrences: <xsl:value-of select="@minOccurs"/></xsl:if> <xsl:if test="@maxOccurs">, max-occurrences: <xsl:value-of select="@maxOccurs"/></xsl:if>;</xsl:otherwise>
+    </xsl:choose></xsl:template>
+    <!--
+  <xsl:template match="xs:complexType">
+    <xsl:apply-templates/>
+  </xsl:template>
+  -->
+  <xsl:template name="generate-name">
+    <xsl:param name="nodes"/>
+    <xsl:param name="name"/>
+    <xsl:choose>
+      <xsl:when test="$nodes">
+        <xsl:call-template name="generate-name">
+          <xsl:with-param name="nodes" select="$nodes[count(.|$nodes[last()]) != count($nodes[last()])]"/>
+          <xsl:with-param name="name" select="concat('-', string($nodes[last()]/@name), string($name))"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="$name"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+  
+  <xsl:template match="xs:simpleContent">
+    <xsl:if test="xs:extension/@base">content :: <xsl:choose><xsl:when test="contains(xs:extension/@base, ':')">&lt;<xsl:call-template name="last-part">
+        <xsl:with-param name="string" select="xs:extension/@base"/>
+        <xsl:with-param name="separator" select="string(':')"/>
+        </xsl:call-template>&gt;</xsl:when>
+        <xsl:when test="/*/xs:simpleType[@name = current()/xs:extension/@base]"><xsl:call-template name="xs:simpleType">
+          <xsl:with-param name="node" select="/*/xs:simpleType[@name = current()/xs:extension/@base]"/>
+        </xsl:call-template></xsl:when>
+      <xsl:otherwise>&lt;string&gt;</xsl:otherwise></xsl:choose>;</xsl:if>
+  </xsl:template>
+
+  <xsl:template match="xs:choice">one-of { <xsl:choose><xsl:when test="xs:any[@namespace='##other']">any </xsl:when><xsl:otherwise><xsl:apply-templates/></xsl:otherwise></xsl:choose>}<xsl:if test="@minOccurs">, min-occurrences: <xsl:value-of select="@minOccurs"/></xsl:if> <xsl:if test="@maxOccurs">, max-occurrences: <xsl:value-of select="@maxOccurs"/></xsl:if>; </xsl:template>
+  
+  <xsl:template match="xs:sequence">sequence-of { <xsl:apply-templates/>}; </xsl:template>    
+  
+  <xsl:template match="xs:attribute">
+    <xsl:if test="@use != 'optional'">required </xsl:if>attribute <xsl:value-of select="@name | @ref"/> :: <xsl:choose>
+        <xsl:when test="@type">&lt;<xsl:call-template name="last-part">
+            <xsl:with-param name="string" select="translate(@type, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
+            <xsl:with-param name="separator" select="string(':')"/>
+          </xsl:call-template>&gt;</xsl:when>
+          <xsl:when test="xs:simpleType"><xsl:call-template name="xs:simpleType">
+            <xsl:with-param name="node" select="xs:simpleType"/> 
+          </xsl:call-template></xsl:when>
+        <xsl:otherwise>&lt;string&gt;</xsl:otherwise>
+        </xsl:choose><xsl:if test="@default"> = <xsl:choose>
+        <xsl:when test="@default = 'true'">#t</xsl:when>
+        <xsl:when test="@default = 'false'">#f</xsl:when>
+        <xsl:otherwise>#"<xsl:value-of select="@default"/>"</xsl:otherwise></xsl:choose></xsl:if>;</xsl:template>
+
+    <xsl:template name="xs:simpleType"><xsl:param name="node"/><xsl:choose>
+        <xsl:when test="$node//xs:enumeration">one-of(<xsl:for-each select="$node/*/xs:enumeration">#"<xsl:value-of select="@value"/>"<xsl:if test="position() != last()">, </xsl:if></xsl:for-each>)</xsl:when>
+        <xsl:when test="$node//xs:restriction">&lt;<xsl:choose><xsl:when test="contains($node//xs:restriction/@base, ':')"><xsl:call-template name="last-part">
+        <xsl:with-param name="string" select="$node//xs:restriction/@base"/>
+        <xsl:with-param name="separator" select="string(':')"/>
+        </xsl:call-template></xsl:when>
+        <xsl:otherwise><xsl:value-of select="$node//xs:restriction/@base"/></xsl:otherwise></xsl:choose>&gt;, check: <xsl:choose>
+          <xsl:when test="$node//xs:restriction/xs:minLength">content.size >= <xsl:value-of select="$node//xs:restriction/xs:minLength/@value"/></xsl:when>
+          <xsl:when test="$node//xs:restriction/xs:pattern">regexp-match(content, "<xsl:value-of select="$node//xs:restriction/xs:pattern/@value"/>")</xsl:when>
+        </xsl:choose></xsl:when>
+      </xsl:choose></xsl:template>
+    
+  <xsl:template match="/*/xs:group">
+    <xsl:choose>
+      <xsl:when test="xs:choice">
+        define constant &lt;<xsl:value-of select="@name"/>&gt;
+          = type-union(<xsl:for-each select="xs:choice/xs:element"><xsl:choose>
+            <xsl:when test="@ref">&lt;<xsl:value-of select="@ref"/>&gt;<xsl:if test="position() != last()">, </xsl:if></xsl:when>
+        </xsl:choose></xsl:for-each>);
+      </xsl:when>
+    </xsl:choose>
+  </xsl:template>
+    
+  <xsl:template name="last-part">
+    <xsl:param name="string"/>
+    <xsl:param name="separator"/>
+    <xsl:choose>
+      <xsl:when test="contains($string, $separator)">
+        <xsl:call-template name="last-part">
+          <xsl:with-param name="string" select="substring-after($string, $separator)"/>
+          <xsl:with-param name="separator" select="$separator"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise><xsl:value-of select="$string"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+  
+</xsl:stylesheet>



More information about the chatter mailing list