Skip to content

Instantly share code, notes, and snippets.

@ctalau
Last active September 16, 2016 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctalau/3ccdfe8a6017618e56acc43c0ae1d5f0 to your computer and use it in GitHub Desktop.
Save ctalau/3ccdfe8a6017618e56acc43c0ae1d5f0 to your computer and use it in GitHub Desktop.
Controlled values in oXygen XML Web Author
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="values.less"?>
<root choices="values2.xml">
<elementWithChoices/>
</root>
// 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;
}
<?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>
<?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