Tesing number of decimal digits in schematron
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 11
- Joined: Thu Nov 21, 2013 3:34 pm
Tesing number of decimal digits in schematron
Hi,
I have another interesting Schematron issue: I need to test that the numeric value should have not more than 3 decimal positions. The data type is xsd:decimal, so there may be also no decimal digits, which makes it more difficult to check (to me anyway). My XML is:
The correct values would be: 5, 5.1, 5.11, but not 5.111
I created the following test using regular expression:
but this requires exactly 2 decimals, which is not the intention. How can I say 0, 1 or 2 decimal digits?
Best Regards,
Ewa
I have another interesting Schematron issue: I need to test that the numeric value should have not more than 3 decimal positions. The data type is xsd:decimal, so there may be also no decimal digits, which makes it more difficult to check (to me anyway). My XML is:
Code: Select all
<A>
<measurement>
<height>5.11</height>
</measurement>
<measurement>
<height>5</height>
</measurement>
</A>
I created the following test using regular expression:
Code: Select all
<sch:rule context="//measurement">
<sch:assert test="height[matches(., '[\.][\d]{2}$')]">Maximum 2 decimal digits are allowed</sch:assert>
</sch:rule>
Best Regards,
Ewa
-
- Posts: 159
- Joined: Mon Nov 24, 2014 1:49 pm
- Location: Greven/Germany
Re: Tesing number of decimal digits in schematron
Hi Ewa,
this should work
The test counts the chars after the '.'.
this should work
The test counts the chars after the '.'.
Code: Select all
<?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">
<sch:pattern>
<sch:rule context="measurement">
<sch:report test="string-length(normalize-space(substring-after(., '.'))) gt 3">
More than 3 decimal positions
</sch:report>
</sch:rule>
</sch:pattern>
</sch:schema>
stefan-jung.org – Your DITA/DITA-OT XML consultant
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service