How to test in Schematron: element value begins with
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 11
- Joined: Thu Nov 21, 2013 3:34 pm
How to test in Schematron: element value begins with
Hi,
I'm a beginner both in schematron and in xpath. I need to write an assertion testing that an element value always begins with a certain string if the attribute has a certain value:
If the attribute is WEBSITE, the communicationChannel value must begin with http:// . Unfortunately, I cannot crack it, would be grateful for any help
That's where I'm stuck. Help please.
Ewa
I'm a beginner both in schematron and in xpath. I need to write an assertion testing that an element value always begins with a certain string if the attribute has a certain value:
Code: Select all
<communicationChannel communicationChannelCode="WEBSITE">http://www.oxygenxml.com</communicationChannel>
Code: Select all
<sch:rule context="communicationChannel/@communicationChannelCode = 'WEBSITE'>
<sch:assert test="communicationChannel [text() ... />
</sch:rule>
Ewa
-
- Posts: 99
- Joined: Thu Oct 23, 2008 6:29 am
Re: How to test in Schematron: element value begins with
Hello. I took a quick look at what you are trying to do. I got it to work with the following changes. You will need to change this if you are using namespaces.
First, here is my sample XML document:
Here is my schema:
First, here is my sample XML document:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="schematron_xml.sch" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<test>
<communicationChannel communicationChannelCode="WEBSITE">http://www.oxygenxml.com</communicationChannel>
<communicationChannel communicationChannelCode="WEBSITE">www.oxygenxml.com</communicationChannel>
</test>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron"
queryBinding="xslt2">
<pattern>
<rule context="/test/communicationChannel">
<assert test="./@communicationChannelCode='WEBSITE' and starts-with(.,'http://')">communicationChannel element must start with 'http://'</assert>
</rule>
</pattern>
</schema>
-
- Posts: 99
- Joined: Thu Oct 23, 2008 6:29 am
Re: How to test in Schematron: element value begins with
There was a bug in my schema above that I am fixing with this change:
I found this issue after running a few more negative test scenarios. The issue was trying to combine two tests in a single assert tripped up the validation. Moving the attribute test to the rule's context resolved this.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron"
queryBinding="xslt2">
<pattern>
<rule context="/test/communicationChannel[@communicationChannelCode='WEBSITE']">
<assert test="starts-with(.,'http://')">communicationChannel element must start with 'http://'</assert>
</rule>
</pattern>
</schema>
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