multiValuesToJSON
The multiValuesToJSON
function is used to serialize a single multivalued attribute to a JSON array.
Syntax
c4i:multivaluesToJSON(xpath [, lov] [, units] [, values])
Parameters
xpath
XPath to a "MultiValue" node
lov (optional)
- Indicates how to represent LOV values
- The authorized values are "DISPLAY_LOV_VALUE_LABEL" (default), "DISPLAY_LOV_VALUE_ID" or "DISPLAY_BOTH"
units (optional)
- Indicates how to represent units
- The authorized values are "NO_UNITS" (default), "DISPLAY_UNIT_ID", "DISPLAY_UNIT_LABEL"
values (optional)
- Indicates if values and units should be concatenated or separated
- The authorized values are "CONCAT_VALUE_UNIT" (default) or "ISOLATE_VALUE"
Return value
A JSON array containing the attribute values.
Example
Given the following STEP XML:
<STEP-ProductInformation>
<UnitList>
<Unit ID="unece.unit.KTM">
<Name>km</Name>
</Unit>
</UnitList>
<AttributeList>
<Attribute ID="ATT2">
<Validation BaseType="number">
<UnitLink UnitID="unece.unit.KTM"/>
</Validation>
</Attribute>
</AttributeList>
<Products>
<Product ID="PRD1">
<Values>
<MultiValue AttributeID="ATT1">
<Value ID="VAL_1">Value 1</Value>
<Value ID="VAL_2">Value 2</Value>
</MultiValue>
<MultiValue AttributeID="ATT2">
<Value UnitID="unece.unit.KTM">16</Value>
<Value UnitID="unece.unit.KTM">12</Value>
</MultiValue>
</Values>
</Product>
</Products>
</STEP-ProductInformation>
The following YAML configurations will produce the following output
YAML Configuration | JSON output |
---|---|
c4i:multiValuesToJSON(Values/MultiValue[@AttributeID="ATT1"], "DISPLAY_LOV_VALUE_LABEL", "NO_UNITS", "CONCAT_VALUE_UNIT") | ["Value 1", "Value 2"] |
c4i:multiValuesToJSON(Values/MultiValue[@AttributeID="ATT1"], "DISPLAY_LOV_VALUE_LABEL", "NO_UNITS", "ISOLATE_VALUE") | [{"value" : "Value 1"}, {"value" : "Value 2"}] |
c4i:multiValuesToJSON(Values/MultiValue[@AttributeID="ATT1"], "DISPLAY_LOV_VALUE_ID", "NO_UNITS", "CONCAT_VALUE_UNIT") | ["VAL_1", "VAL_2"] |
c4i:multiValuesToJSON(Values/MultiValue[@AttributeID="ATT1"], "DISPLAY_LOV_VALUE_ID", "NO_UNITS", "ISOLATE_VALUE") | [{"value" : "VAL_1"}, {"value" : "VAL_2"}] |
c4i:multiValuesToJSON(Values/MultiValue[@AttributeID="ATT1"], "DISPLAY_BOTH") | [{"id" : "VAL_1", "label": "Value 1"}, {"id" : "VAL_2", "label": "Value 2"}] |
c4i:multiValuesToJSON(Values/MultiValue[@AttributeID="ATT2"], "DISPLAY_LOV_VALUE_LABEL", "NO_UNITS", "CONCAT_VALUE_UNIT") | [16, 12] |
c4i:multiValuesToJSON(Values/MultiValue[@AttributeID="ATT2"], "DISPLAY_LOV_VALUE_LABEL", "NO_UNITS", "ISOLATE_VALUE") | [{"value": 16}, {"value": 12}] |
c4i:multiValuesToJSON(Values/MultiValue[@AttributeID="ATT2"], "DISPLAY_LOV_VALUE_LABEL", "DISPLAY_UNIT_ID", "CONCAT_VALUE_UNIT") | ["16 unece.unit.KTM", "12 unece.unit.KTM"] |
c4i:multiValuesToJSON(Values/MultiValue[@AttributeID="ATT2"], "DISPLAY_LOV_VALUE_LABEL", "DISPLAY_UNIT_ID", "ISOLATE_VALUE") | [{"value":16, "unit":"unece.unit.KTM"}, {"value":12, "unit":"unece.unit.KTM"}] |
c4i:multiValuesToJSON(Values/MultiValue[@AttributeID="ATT2"], "DISPLAY_LOV_VALUE_LABEL", "DISPLAY_UNIT_LABEL", "CONCAT_VALUE_UNIT") | ["16 km", "12 km"] |
c4i:multiValuesToJSON(Values/MultiValue[@AttributeID="ATT2"], "DISPLAY_LOV_VALUE_LABEL", "DISPLAY_UNIT_LABEL", "ISOLATE_VALUE") | [{"value":16, "unit": "km"}, {"value":12, "unit":"km"}] |