xslt - Display XSD-defined default value of attribute using XSL -
I thought it should be easy to find, yet after some searching I found it to be clearly defined Would be good for
In my XSD I have defined an enum derived from the string. In a complex type I have defined and the attribute that refers to this enum, with a default value.
In my XSL I want to display the default value of this attribute for elements whose properties are not explicitly set.
XSD:
& lt; X: complex type name = "foo" & gt; & Lt; Xs: attribute name = "bar" type = "response_code bar-type" default = "default" /> & Lt; / XS: complexType & gt; & Lt; X: simple type name = "bartype" & gt; & Lt; Xs: restriction base = "xs: string" & gt; & Lt; Xs: calculation 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: Calculation & gt; & Lt; Xs: calculation 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: Calculation & gt; & Lt; / XS: Ban & gt; & Lt; / XS: simpleType & gt;
XML:
.... Foo / & gt; & Lt; Foo bar = "default" /> & Lt; Foo bar = "chocolate" /> ....
I hope that XSL should be: (more or less)
& Lt; / Li & gt; & Lt; / XSL: for-each & gt; & Lt; / Ol & gt;
Now when I display this style XML file, the value of the 'bar' attribute is empty for the exact value, while I want to display (or select) bar type:
Now:
- < / P>
- Bar type: 'default'
- Bar type: 'default'
- Bar type: 'chocolate'
Preferred:
Now it should be quite simple,
Maybe I'm more general OE, but if you want to load the default schema, you'll need something along the lines of this:
& lt; Xsl: stylesheet version = "1.0" Xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" xmlns: xs = "http://www.w3.org/2001/XMLSchema" Out- Result-prefix = "xs" & gt; & Lt; Xsl: variable name = "schema" = "document ('responsecodes.xsd')" /> & Lt; Xsl: variable name = "DefaultBar" = "$ schema // X: complex type [@ name = 'afu'] / xs: attribute [@ name = 'bar'] / @ default" /> & Lt; Xsl: template match = "foo" & gt; & Lt; Li & gt; & Lt; Xsl: text & gt; Bar type: '& lt; / Xsl: text & gt; & Lt; XSL: Select & gt; & Lt; Xsl: when test = "@ bar" & gt; & Lt; Xsl: Select Value = "@ Bar" /> & Lt; / XSL: When & gt; & Lt; XSL: otherwise & gt; & Lt; Xsl: Select Value = "$ DefaultBar" /> & Lt; / XSL: otherwise & gt; & Lt; / XSL: Select & gt; & Lt; XSL: Text & gt; '& Lt; / XSL: text & gt; & Lt; / Li & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt;
Comments
Post a Comment