XSLT: Get enumeration from xsd

2019-03-02 06:05发布

问题:

I've this enum in the xsd file:

<xs:simpleType name="SO"> 
    <xs:restriction base="xs:string"> 
        <xs:enumeration value="Mac OS X"/>
        <xs:enumeration value="Windows Server"/>
        <xs:enumeration value="Windows Vista"/>
        <xs:enumeration value="Windows XP"/> 
        <xs:enumeration value="Windows 7"/>
        <xs:enumeration value="Windows 8"/>
        <xs:enumeration value="Windows 8.1"/>
        <xs:enumeration value="Ubuntu"/> 
    </xs:restriction> 
</xs:simpleType>

and I need to get it in the XSL to use it in a javascript combobox. There's any way to do it?

回答1:

This stylesheet will output a list of <option/>s:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xsl:template match="xs:simpleType[@name='SO']/xs:restriction">
    <xsl:for-each select="xs:enumeration"><option><xsl:value-of select="@value"/></option></xsl:for-each>
  </xsl:template>
</xsl:stylesheet>