:rule context=" " subject=" "
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 19
- Joined: Fri Apr 18, 2014 1:07 am
- Contact:
:rule context=" " subject=" "
Are there more example to use the "subject within rule context? (<sch:rule context="blah/blah/blah" subject=""> )
See, I was task to be more specific..have a way to check if a value is there, if so, then run "assert" within the <pattern>.
We know <rule context=" "> is where the context attribute is. But we want to have like a IF-Statement or if value is there then go ahead and run the <pattern>, If not, don't proceed on.
See, I was task to be more specific..have a way to check if a value is there, if so, then run "assert" within the <pattern>.
We know <rule context=" "> is where the context attribute is. But we want to have like a IF-Statement or if value is there then go ahead and run the <pattern>, If not, don't proceed on.
-
- Posts: 99
- Joined: Thu Oct 23, 2008 6:29 am
Re: :rule context=" " subject=" "
I don't have an example where subject is used; however, can't you do what you are looking for with XPath criteria within the context attribute?
Something like this:
Something like this:
Code: Select all
<pattern>
<rule context="/node/subNode[@atttibute='TARGET'][count(@attributeThatMustExist)>0]">
<assert test=".!='whatever'">Error condition</assert>
</rule>
</pattern>
-
- Posts: 19
- Joined: Fri Apr 18, 2014 1:07 am
- Contact:
Re: :rule context=" " subject=" "
Thanks Jamil.
I like how you have the "[count(@attributeThatMustExist)>0]". But my problem is this. I want to check that the attribute is located in another node. If it does, then in a different node I want to run the assert to test that node/subnode's Properties exist. The reason is that to run the assert test, those properties are only for those that particular 1st node.
Here is a more generic term without going into my work's elements.
Node
Car->Toyota->Prius
Car->Ford->Mustang
Suv->Ford->Explorer
Node
Gas--attributes: 1)Mileage on gas, 2)Total Mileage distance
Hybrid--attribute: 1) Mile on electric, 2)Mileage on city, 3)mileage on highway.
See, due to Prius is a Hybrid I just want to test the hybrid part and the Prius should not run through the gas element. In the Node with gas...I need check in "sch:rule context" to look at the Node Car. I guess its checking for its reference.
Is that a little help?
I like how you have the "[count(@attributeThatMustExist)>0]". But my problem is this. I want to check that the attribute is located in another node. If it does, then in a different node I want to run the assert to test that node/subnode's Properties exist. The reason is that to run the assert test, those properties are only for those that particular 1st node.
Here is a more generic term without going into my work's elements.
Node
Car->Toyota->Prius
Car->Ford->Mustang
Suv->Ford->Explorer
Node
Gas--attributes: 1)Mileage on gas, 2)Total Mileage distance
Hybrid--attribute: 1) Mile on electric, 2)Mileage on city, 3)mileage on highway.
See, due to Prius is a Hybrid I just want to test the hybrid part and the Prius should not run through the gas element. In the Node with gas...I need check in "sch:rule context" to look at the Node Car. I guess its checking for its reference.
Is that a little help?
-
- Posts: 99
- Joined: Thu Oct 23, 2008 6:29 am
Re: :rule context=" " subject=" "
Okay. Try this:
This worked against a test document I created below:
You'll want to run some performance tests with this against large XML documents due to using //*
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<pattern>
<rule context="//*[count(@MileageOnElectric)>0]">
<assert test="./@MileageOnCity > 30 or ./@MileageOnHighway > 50">Poor mileage for a hybrid</assert>
</rule>
<rule context="//*[count(@MileageOnGas)>0]">
<assert test="./@TotalMileageDistance > 60">Poor mileage for a gasolene vehicle</assert>
</rule>
</pattern>
</schema>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="schematron_question2.sch" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<auto>
<Car>
<Toyota>
<Prius MileageOnElectric="30" MileageOnCity="35" MileageOnHighway="10"/>
</Toyota>
<Ford>
<Mustang MileageOnGas="15" TotalMileageDistance="80"/>
</Ford>
</Car>
<Suv>
<Ford>
<Explorer MileageOnGas="10" TotalMileageDistance="61"/>
</Ford>
</Suv>
</auto>
-
- Posts: 19
- Joined: Fri Apr 18, 2014 1:07 am
- Contact:
Re: :rule context=" " subject=" "
Thanks....I will try later. But many thanks and I will keep you updated!
-
- Posts: 99
- Joined: Thu Oct 23, 2008 6:29 am
Re: :rule context=" " subject=" "
No problem. Taking a second look at this, the or in my first assert test should really be an and. This revised schema resolves the issue:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<pattern>
<rule context="//*[count(@MileageOnElectric)>0]">
<assert test="./@MileageOnCity > 30 and ./@MileageOnHighway > 50">Poor mileage for a hybrid</assert>
</rule>
<rule context="//*[count(@MileageOnGas)>0]">
<assert test="./@TotalMileageDistance > 60">Poor mileage for a gasolene vehicle</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