我认为这应该很容易找到,但经过一番搜索,我发现这可能很好定义清楚。
在我的 XSD 中,我定义了一个从字符串派生的枚举。在我定义的复杂类型和引用此枚举的属性中,具有默认值。
在我的 XSL 中,我希望为未明确设置属性的元素显示此属性的默认值。
XSD:
<xs:complexType name="foo">
<xs:attribute name="bar" type="responsecodes:barType" default="default"/>
</xs:complexType>
<xs:simpleType name="barType">
<xs:restriction base="xs:string">
<xs:enumeration value="default">
<xs:annotation>
<xs:documentation xml:lang="en-us">Default bar.</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="chocolate">
<xs:annotation>
<xs:documentation xml:lang="en-us">A chocolate ...bar</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
XML:
....
<foo/>
<foo bar="default"/>
<foo bar="chocolate"/>
....
我希望 XSL 是:(或多或少)
<ol>
<xsl:for-each select="/foo">
<li>BarType: '<xsl:value-of select="@bar" />'</li>
</xsl:for-each>
</ol>
现在,当我显示此样式 XML 文件时,'bar' 属性的值对于未指定的值是空的,而我希望显示(或选择)默认值。
现在:
- 栏类型:''
- 栏类型:'默认'
- BarType: '巧克力'
期望:
- 栏类型:'默认'
- 栏类型:'默认'
- BarType: '巧克力'
现在这应该很简单,不是吗?