Last active
September 16, 2016 11:13
-
-
Save ctalau/3ccdfe8a6017618e56acc43c0ae1d5f0 to your computer and use it in GitHub Desktop.
Controlled values in oXygen XML Web Author
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?xml-stylesheet type="text/css" href="values.less"?> | |
<root choices="values2.xml"> | |
<elementWithChoices/> | |
</root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// By default, load the values.xml file from the framewotk directory. | |
:root elementWithChoices { | |
.controlled-values(oxy_url("${framework}", "values.xml")); | |
} | |
// If specified in the root element, another choices file is used. | |
:root[choices] elementWithChoices { | |
.controlled-values(oxy_xpath("/*/@choices", processChangeMarkers, false, evaluate, dynamic-once)); | |
} | |
.controlled-values(@valuesFile) { | |
//The oxy_concat expression just composes an XPath expression like the one below: | |
// | |
// string-join(doc('values.xml')//my-element-name/*/text(), ',') | |
// | |
@xpath: oxy_concat("string-join(doc('", @valuesFile, "')//", oxy_name(), "/*/text(), ',')"); | |
content: oxy_combobox( | |
edit, '#text', | |
editable, false, | |
values, oxy_xpath(@xpath, processChangeMarkers, false, static) | |
); | |
visibility: -oxy-collapse-text; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2" | |
xmlns:sqf="http://www.schematron-quickfix.com/validator/process"> | |
<!-- General variables for the whole document. --> | |
<sch:let name="doc-uri" value="base-uri(.)"/> | |
<sch:let name="choices-file" value="/*/@choices"/> | |
<sch:let name="values-uri" value="resolve-uri($choices-file, $doc-uri)"/> <!-- Here we compute the location of the 'values.xml' file --> | |
<sch:let name="values-for-elements" value="doc($values-uri)"/> | |
<!-- Abstract pattern to be instantiated for each element with constrained values --> | |
<sch:pattern abstract="true" id="value-constraint"> | |
<sch:title>Constrain element values</sch:title> | |
<sch:rule context="$element-name"> | |
<sch:let name="crt-text" value="text()"/> | |
<sch:let name="choices" value="$values-for-elements//$element-name/*/text()"/> | |
<sch:let name="matches" value="$values-for-elements//$element-name/*[text() = $crt-text]/text()"/> | |
<sch:assert test="not(empty($matches))"> | |
Invalid value for element <sch:value-of select="local-name(.)"/>: "<sch:value-of select="$crt-text"/>" is not among <sch:value-of select="string-join($choices, ',')"/> | |
</sch:assert> | |
</sch:rule> | |
</sch:pattern> | |
<!-- This is an instance of the rule for a particular element --> | |
<sch:pattern is-a="value-constraint"> | |
<sch:param name="element-name" value="elementWithChoices"/> | |
</sch:pattern> | |
</sch:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<values> | |
<elementWithChoices> | |
<value>x1</value> | |
<value>x2</value> | |
<value>x3</value> | |
</elementWithChoices> | |
</values> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment