以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DTD/XML Schema 』  (http://bbs.xml.org.cn/list.asp?boardid=23)
----  [原创]关于xsd定义函数规则的问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=23&rootid=&id=55679)


--  作者:zhaoyta
--  发布时间:11/20/2007 2:32:00 PM

--  [原创]关于xsd定义函数规则的问题
各位好,CREATE FUNCTION [dbo].[fn_ScoreDerivedFeatureMiningModel](
  @D varchar(255),
  @VENDOR_LEAD_SOURCE varchar(255),
  @PURCHASE_TIMEFRAME varchar(255),
  @ORIGINAL_REQUESTED_MODEL varchar(255),
  @REQUESTED_MODEL_SEGMENTA2 varchar(255),
  @ORIGINAL_REQUESTED_MAKE varchar(255))
  RETURNS INT
AS
BEGIN
  DECLARE @score INT
  IF @D <= '2007-03-01' SET @score = 10000
  ELSE IF @VENDOR_LEAD_SOURCE = 'EPDN'  SET @score = 899
       ELSE IF @PURCHASE_TIMEFRAME = '48 hours to 1 week' SET @score = 879
            ELSE  IF @ORIGINAL_REQUESTED_MODEL = 'camry' SET @score = 674
                  ELSE IF @PURCHASE_TIMEFRAME = 'Week' SET @score = 596
                       ELSE IF @REQUESTED_MODEL_SEGMENTA2 <> ' '
                              IF @REQUESTED_MODEL_SEGMENTA2 = 'HYBRID' SET @score = 621
                              ELSE IF @VENDOR_LEAD_SOURCE <> 'GMBP'
                                     IF @ORIGINAL_REQUESTED_MAKE = 'toyota' SET @score = 552
                                     ELSE SET @score = 0   
                                   ELSE SET @score = 0
                            ELSE SET @score = 0
  RETURN @score
END

在sql有这么一段规则,返回分数,

现在要改成用xml实现这段规则

xsd文件已经定义好

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
 <xs:element name="DecisionTree">
  <xs:annotation>
   <xs:documentation>Decision Tree Model XML Representation</xs:documentation>
  </xs:annotation>
  <xs:complexType>
   <xs:sequence>
    <xs:element name="Node">
     <xs:complexType>
      <xs:sequence>
       <xs:element name="Node" type="NodeType" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="score" type="xs:decimal" use="required" fixed="-1"/>
     </xs:complexType>
    </xs:element>
   </xs:sequence>
   <xs:attribute name="type" type="xs:string" use="required"/>
   <xs:attribute name="target" type="xs:string" use="required"/>
   <xs:attribute name="version" type="xs:string" use="required"/>
  </xs:complexType>
 </xs:element>
 <xs:complexType name="NodeType">
  <xs:sequence>
   <xs:choice>
    <xs:element name="predicate" type="SamplePredicateType"/>
    <xs:element name="compound-predicate" type="CompoundPredicateType"/>
   </xs:choice>
   <xs:element name="Node" type="NodeType" minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>
  <xs:attribute name="score" type="xs:decimal" use="required"/>
 </xs:complexType>
 <xs:complexType name="CompoundPredicateType">
  <xs:sequence>
   <xs:element name="predicate" type="SamplePredicateType" minOccurs="2" maxOccurs="unbounded"/>
  </xs:sequence>
  <xs:attribute name="op" type="operator" use="required"/>
 </xs:complexType>
 <xs:complexType name="SamplePredicateType">
  <xs:sequence>
   <xs:element name="simple-attribute">
    <xs:complexType>
     <xs:attribute name="name" type="xs:string" use="required"/>
    </xs:complexType>
   </xs:element>
  </xs:sequence>
  <xs:attribute name="op" type="operator" use="required"/>
  <xs:attribute name="value" type="xs:string" use="required"/>
 </xs:complexType>
 <xs:simpleType name="operator">
        <xs:restriction base="xs:string">
        <xs:enumeration value="lt"/>
        <xs:enumeration value="le"/>
        <xs:enumeration value="eq"/>
        <xs:enumeration value="gt"/>
        <xs:enumeration value="ge"/>
        <xs:enumeration value="ne"/>
        <xs:enumeration value="and"/>
        <xs:enumeration value="or"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

请达人给点思路  谢谢


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms