Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay XSD-defined default value of attribute using XSL
    primarykey
    data
    text
    <p>I thought this ought to be simple to find, yet after some searching I found this might be nice to define clearly.</p> <p>In my XSD I've defined an enum, derived from string. In a complex type I've defined and attribute that refers to this enum, with a default value.</p> <p>In my XSL I wish to display the default value of this attribute for elements whose attribute is not explicitly set.</p> <p>The XSD:</p> <pre><code>&lt;xs:complexType name="foo"&gt; &lt;xs:attribute name="bar" type="responsecodes:barType" default="default"/&gt; &lt;/xs:complexType&gt; &lt;xs:simpleType name="barType"&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:enumeration value="default"&gt; &lt;xs:annotation&gt; &lt;xs:documentation xml:lang="en-us"&gt;Default bar.&lt;/xs:documentation&gt; &lt;/xs:annotation&gt; &lt;/xs:enumeration&gt; &lt;xs:enumeration value="chocolate"&gt; &lt;xs:annotation&gt; &lt;xs:documentation xml:lang="en-us"&gt;A chocolate ...bar&lt;/xs:documentation&gt; &lt;/xs:annotation&gt; &lt;/xs:enumeration&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; </code></pre> <p>The XML:</p> <pre><code>.... &lt;foo/&gt; &lt;foo bar="default"/&gt; &lt;foo bar="chocolate"/&gt; .... </code></pre> <p>I'd expect the XSL to be: (more or less)</p> <pre><code>&lt;ol&gt; &lt;xsl:for-each select="/foo"&gt; &lt;li&gt;BarType: '&lt;xsl:value-of select="@bar" /&gt;'&lt;/li&gt; &lt;/xsl:for-each&gt; &lt;/ol&gt; </code></pre> <p>Now when I display this style XML file, the value of the 'bar' attribute is empty for the non-specified value, while I'd wish to display (or select on) the default value.</p> <p>Now:</p> <ol> <li>BarType: ''</li> <li>BarType: 'default'</li> <li>BarType: 'chocolate'</li> </ol> <p>Desired:</p> <ol> <li>BarType: 'default'</li> <li>BarType: 'default'</li> <li>BarType: 'chocolate'</li> </ol> <p>Now this ought to be quite simple, no?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload