Reputation: 61
I have this XSD Enumeration :
<xs:element name="NeedEnum" type="my:Enum" />
<xs:simpleType name="Enum">
<xs:restriction base="xs:string">
<xs:enumeration value="Enumeration 1" id="E_1" />
<xs:enumeration value="Enumeration 2" id="E_2" />
<xs:enumeration value="Enumeration 3" id="E_3" />
<xs:enumeration value="Enumeration 4" id="E_4" />
</xs:restriction>
</xs:simpleType>
I want to be able to use this simple type/enumeration into a XSLT File to be able to have an HTML select populated with those values.
This is my XSLT File so far (just the table part, not all the namespaces) :
<div>
<select title="Enum" class="">
<xsl:for-each select="Enum">
<option>
<xsl:value-of select="./@value"/>
</option>
</xsl:for-each>
<option>
<xsl:value-of select="NeedEnum"/>
</option>
</select>
</div>
I know that my XSLT file is way off, but I would like to have a select with the value of the options being the enumeration id and the "caption" being the value of the enumeration. I mean I've been reading for a couple of hours and I didn't find anything that could've helped me.
I want to have something like this linked to my NeedEnum :
<select title="Enum" >
<option value="E_1" >Enumeration 1</option>
<option value="E_2" >Enumeration 2</option>
<option value="E_3" >Enumeration 3</option>
<option value="E_4" >Enumeration 4</option>
</select>
Can you help me?
Upvotes: 0
Views: 708
Reputation: 163458
You haven't said anything about your processing environment, but if this is a schema-aware transformation using Saxon-EE, then when $e
is bound to the (schema-validated) NeedEnum
element:
let $t := saxon:type($e)
returns (a representation of) the simple type Enum
let $f := $t('facets')[.('class')='enumeration']
returns its enumeration facet
let $v := $f('values')
returns the enumeration values as a sequence of strings.
So you can write:
<xsl:for-each select="saxon:type($e)('facets')[.('class')='enumeration']('values')">
<option value="E_{position()}"><xsl:value-of select="."/></option>
</xsl:for-each>
The id
attributes in the schema, unfortunately, are not available.
(Not tested.)
Upvotes: 1