新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论XSL,XSLT,XSL-FO,CSS等技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 XSL/XSLT/XSL-FO/CSS 』 → XMI到XML Schema的XSLT转换例子,我遇到问题! 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 3075 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: XMI到XML Schema的XSLT转换例子,我遇到问题! 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     wxb_nudt 帅哥哟,离线,有人找我吗?
      
      
      等级:大三(要不要学学XML呢?)
      文章:72
      积分:505
      门派:XML.ORG.CN
      注册:2004/12/9

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给wxb_nudt发送一个短消息 把wxb_nudt加入好友 查看wxb_nudt的个人资料 搜索wxb_nudt在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看wxb_nudt的博客楼主
    发贴心情 XMI到XML Schema的XSLT转换例子,我遇到问题!

    本例子来源于http://www-900.ibm.com/developerWorks/cn/xml/x-wxxm25/
    我使用XMLSPY2004做XSLT转换时报错,先列举源文件如下,希望大家一起做出来:
    XMI文件:ModelAddress1.xml
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="ModelAddress1.xsl"?>
    <XMI xmi.version="1.2" xmlns:UML="org.omg/UML/1.4">
     <XMI.header>
      <XMI.documentation>
       <XMI.exporter>ananas.org stylesheet</XMI.exporter>
      </XMI.documentation>
      <XMI.metamodel xmi.name="UML" xmi.version="1.4"/>
     </XMI.header>
     <XMI.content>
      <UML:Model xmi.id="M.1" name="address" visibility="public" isSpecification="fase" isRoot="false" isLeaf="false" isAbstract="false">
       <UML:Namespace.ownedElement>
        <UML:Stereotype xmi.id="S.1" name="root" visibility="public" isSpecification="false" baseClass="Class">
                </UML:Stereotype>
        <UML:TagDefinition xmi.id="TD.1" name="position" isSpecification="false" tagType="String">
         <UML:TagDefinition.owner>
          <UML:Stereotype xmi.id="S.1"/>
         </UML:TagDefinition.owner>
        </UML:TagDefinition>
        <UML:Class xmi.id="C.1" name="person" visibility="public" isSpecification="false" namespace="M.1" isRoot="true" isLeaf="true" isAbstract="false" isActive="false">
         <UML:ModelElement.stereotype>
          <UML:Stereotype xmi.idref="S.1"/>
         </UML:ModelElement.stereotype>
         <UML:Classifier.feature>
          <UML:Attribute xmi.id="A.1" name="name" visibility="private" isSpecification="false" ownerScope="instance"/>
          <UML:Attribute xmi.id="A.2" name="telephone" visibility="private" isSpecification="false" ownerScope="instance">
           <UML:StructuralFeature.multiplicity>
            <UML:Multiplicity>
             <UML:Multiplicity.range>
              <UML:MultiplicityRange lower="0" upper="5"/>
             </UML:Multiplicity.range>
            </UML:Multiplicity>
           </UML:StructuralFeature.multiplicity>
          </UML:Attribute>
          <UML:Attribute xmi.id="A.3" name="fax" visibility="private" isSpecification="false" ownerScope="instance">
           <UML:StructuralFeature.multiplicity>
            <UML:Multiplicity>
             <UML:Multiplicity.range>
              <UML:MultiplicityRange lower="0" upper="5"/>
             </UML:Multiplicity.range>
            </UML:Multiplicity>
           </UML:StructuralFeature.multiplicity>
          </UML:Attribute>
          <UML:Attribute xmi.id="A.4" name="email" visibility="private" isSpecification="false" ownerScope="instance">
           <UML:StructuralFeature.multiplicity>
            <UML:Multiplicity>
             <UML:Multiplicity.range>
              <UML:MultiplicityRange lower="0" upper="5"/>
             </UML:Multiplicity.range>
            </UML:Multiplicity>
           </UML:StructuralFeature.multiplicity>
          </UML:Attribute>
         </UML:Classifier.feature>
        </UML:Class>
        <UML:Class xmi.id="C.2" name="address" visibility="public" isSpecification="false" namespace="M.1" isRoot="true" isLeaf="true" isAbstract="false" isActive="false">
         <UML:Classifier.feature>
          <UML:Attribute xmi.id="A.5" name="name" visibility="private" isSpecification="false" ownerScope="instance"/>
          <UML:Attribute xmi.id="A.6" name="street" visibility="private" isSpecification="false" ownerScope="instance"/>
          <UML:Attribute xmi.id="A.7" name="zip" visibility="private" isSpecification="false" ownerScope="instance"/>
          <UML:Attribute xmi.id="A.8" name="region" visibility="private" isSpecification="false" ownerScope="instance"/>
          <UML:Attribute xmi.id="A.9" name="city" visibility="private" isSpecification="false" ownerScope="instance"/>
          <UML:Attribute xmi.id="A.10" name="country" visibility="private" isSpecification="false" ownerScope="instance"/>
         </UML:Classifier.feature>
        </UML:Class>
        <UML:Class xmi.id="C.3" name="job" visibility="public" isSpecification="false" namespace="M.1" isRoot="true" isLeaf="true" isAbstract="false" isActive="false">
         <UML:Classifier.feature>
          <UML:Attribute xmi.id="A.11" name="title" visibility="private" isSpecification="false" ownerScope="instance"/>
          <UML:Attribute xmi.id="A.12" name="organization" visibility="private" isSpecification="false" ownerScope="instance"/>
         </UML:Classifier.feature>
        </UML:Class>
        <UML:Association xmi.id="A.1" isSpecification="false">
         <UML:ModelElement.taggedValue>
          <UML:TaggedValue xmi.id="T.1" isSpecification="false" dataValue="20">
           <UML:TaggedValue.type>
            <UML:TagDefinition xmi.idref="TD.1"/>
           </UML:TaggedValue.type>
          </UML:TaggedValue>
         </UML:ModelElement.taggedValue>
         <UML:Association.connection>
          <UML:AssociationEnd xmi.id="AE.1" visibility="public" isSpecification="false" isNavigable="true">
           <UML:AssociationEnd.participant>
            <UML:Class xmi.idref="C.1"/>
           </UML:AssociationEnd.participant>
          </UML:AssociationEnd>
          <UML:AssociationEnd xmi.id="AE.2" visibility="public" isSpecification="false" isNavigable="true">
           <UML:AssociationEnd.participant>
            <UML:Class xmi.idref="C.2"/>
           </UML:AssociationEnd.participant>
           <UML:AssociationEnd.multiplicity>
            <UML:Multiplicity>
             <UML:Multiplicity.range>
              <UML:MultiplicityRange lower="1" upper="5"/>
             </UML:Multiplicity.range>
            </UML:Multiplicity>
           </UML:AssociationEnd.multiplicity>
          </UML:AssociationEnd>
         </UML:Association.connection>
        </UML:Association>
        <UML:Association xmi.id="A.2" isSpecification="false">
         <UML:ModelElement.taggedValue>
          <UML:TaggedValue xmi.id="T.2" isSpecification="false" dataValue="120">
           <UML:TaggedValue.type>
            <UML:TagDefinition xmi.idref="TD.1"/>
           </UML:TaggedValue.type>
          </UML:TaggedValue>
         </UML:ModelElement.taggedValue>
         <UML:Association.connection>
          <UML:AssociationEnd xmi.id="AE.3" visibility="public" isSpecification="false" isNavigable="true">
           <UML:AssociationEnd.participant>
            <UML:Class xmi.idref="C.1"/>
           </UML:AssociationEnd.participant>
          </UML:AssociationEnd>
          <UML:AssociationEnd xmi.id="AE.4" visibility="public" isSpecification="false" isNavigable="true">
           <UML:AssociationEnd.participant>
            <UML:Class xmi.idref="C.3"/>
           </UML:AssociationEnd.participant>
          </UML:AssociationEnd>
         </UML:Association.connection>
        </UML:Association>
       </UML:Namespace.ownedElement>
      </UML:Model>
     </XMI.content>
    </XMI>


    XSL文件:ModelAddress1.xsl
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:xs="http://www.w3.org/2001/XMLSchema"
                    xmlns:xi="http://ananas.org/2002/xi/rules"
                    xmlns:UML="org.omg/UML/1.4"
                    exclude-result-prefixes="UML"
                    version="1.0"
                    xmlns:xalan="http://xml.apache.org/xslt">

    <xsl:output xi:suffix="xsd" indent="yes" xalan:indent-amount="2"/>

    <xsl:variable name="root-id" select="/XMI/XMI.content/UML:Model/UML:Namespace.ownedElement/UML:Stereotype[@name='root']/@xmi.id"/>
    <xsl:variable name="position-id" select="/XMI/XMI.content/UML:Model/UML:Namespace.ownedElement/UML:TagDefinition[@name='position']/@xmi.id"/>

    <xsl:template match="XMI[@xmi.version='1.2']">
       <xsl:apply-templates select="XMI.content/UML:Model"/>
    </xsl:template>

    <xsl:template match="XMI">
       <xsl:message terminate="yes">Unknown XMI version</xsl:message>
    </xsl:template>

    <xsl:template match="UML:Model">
       <xs:schema targetNamespace="http://psol.com/uml/{@name}">
          <xsl:apply-templates select="UML:Namespace.ownedElement/UML:Class[UML:ModelElement.stereotype/UML:Stereotype/@xmi.idref=$root-id]"/>
       </xs:schema>
    </xsl:template>

    <xsl:template match="UML:Class">
       <xsl:param name="multiplicity"/>
       <xsl:variable name="id" select="@xmi.id"/>
       <xs:element name="{@name}">
          <!-- test because the processor reports an error if the parameter was not set
               (i.e. for root elements, the parameter is never set)                     -->
          <xsl:if test="$multiplicity">
             <xsl:apply-templates select="$multiplicity"/>
          </xsl:if>
          <xs:complexType>
             <xs:sequence>
                <xsl:apply-templates/>
                <xsl:apply-templates select="//UML:Association[UML:Association.connection/UML:AssociationEnd[1]/UML:AssociationEnd.participant/UML:Class[@xmi.idref=$id]]"
                                     mode="association">
                   <xsl:sort select="UML:ModelElement.taggedValue/UML:TaggedValue[UML:TaggedValue.type/UML:TagDefinition[@xmi.idref=$position-id]]/@dataValue"
                             data-type="number"/>
                </xsl:apply-templates>
             </xs:sequence>
          </xs:complexType>
       </xs:element>
    </xsl:template>

    <xsl:template match="UML:Association" mode="association">
       <xsl:variable name="id" select="UML:Association.connection/UML:AssociationEnd[2]/UML:AssociationEnd.participant/UML:Class/@xmi.idref"/>
       <xsl:apply-templates select="//UML:Class[@xmi.id=$id]" mode="association">
          <xsl:with-param name="multiplicity" select=".//UML:MultiplicityRange"/>
       </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="UML:Class[UML:ModelElement.stereotype/UML:Stereotype/@xmi.idref=$root-id]" mode="association">
       <xsl:param name="multiplicity"/>
       <xs:element ref="{@name}">
          <xsl:apply-templates select="$multiplicity"/>
       </xs:element>
    </xsl:template>

    <xsl:template match="UML:Class" mode="association">
       <xsl:param name="multiplicity"/>
       <xsl:apply-templates select=".">
          <xsl:with-param name="multiplicity" select="$multiplicity"/>
       </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="UML:Attribute">
       <xs:element name="{@name}" type="xs:string">
          <xsl:apply-templates select=".//UML:MultiplicityRange"/>
       </xs:element>
    </xsl:template>

    <xsl:template match="UML:MultiplicityRange">
       <xsl:if test="@lower and number(@lower) != 1">
          <xsl:attribute name="minOccurs"><xsl:value-of select="@lower"/></xsl:attribute>
       </xsl:if>
       <xsl:choose>
          <xsl:when test="@upper and number(@upper) = -1">
             <xsl:attribute name="maxOccurs">unbounded</xsl:attribute>
          </xsl:when>
          <xsl:when test="@upper and number(@upper) != 1">
             <xsl:attribute name="maxOccurs"><xsl:value-of select="@upper"/></xsl:attribute>
          </xsl:when>
       </xsl:choose>
    </xsl:template>

    <xsl:template match="text()">
       <xsl:value-of select="normalize-space(.)"/>
    </xsl:template>

    </xsl:stylesheet>

    XMLSPY报错为:
    此表达式中不能使用变量
    UML:Class[UML:ModelElement.steroetype/UML:Steroetype/@xmi.idref=$root-id]
    它说这个root-id不能在这儿使用??


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    我的blog:MDA之路!欢迎讨论MDA,XML,UML,Eclipse,JAVA的朋友来看看。
    http://www.blogjava.net/wxb_nudt/

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/12/14 10:20:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2025/7/30 0:56:08

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    156.006ms