[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Schematron and RNG, RNC

  • From: Alex Muir <alex.g.muir@gmail.com>
  • To: John Cowan <cowan@mercury.ccil.org>
  • Date: Fri, 3 Feb 2012 17:14:07 +0000

Re:  Schematron and RNG
Well the other thing I'm not clear on is that for the RNG the schematron logic can be placed after the top level grammar element,, for the RNC I'm getting syntax error

# 1. Whenever condition attribute is used the element
# should have have an xml:id or cref attribute
#
# condition="dig" cref="EWPB_Chinese_test_p54_1_warmup_1"
#

s:pattern [
  id = "condition.checks"

  s:title [ "Whenever condition attribute is used the element should have have an xml:id or cref attribute" ]
  s:rule [
    context = "*[exists(@condition)]"

    s:assert [ test = "exists(@cref) or exists(@xml:id)" "There should be an xml:id or cref attribute" ]
  ]
]
s:pattern [
  id = "cref.checks"

  s:title [ "cref points to element with matching xml:id" ]
  s:rule [
    context = "*[exists(@cref)]"
    s:assert [
      test = "exists(//*[matches(@xml:id,current()/@cref)])"
      " cref does not point to element with matching xml:id"
    ]
  ]]
s:pattern [
  id = "component.checks"

  s:title [ "components have xml:id" ]
  s:rule [
    context =
      "db:book | db:part | db:preface | db:chapter | db:appendix | db:glossary |          db:bibliography | db:article"

    s:assert [ test = "exists(@xml:id)" "every component should have an xml:id" ]
  ]]
s:pattern [
  id = "section.checks"

  s:title [ "sections have xml:id" ]
  s:rule [
    context = "db:section | db:simplesect | db:bridgehead | db:dlossdiv | db:bibliodiv"

    s:assert [ test = "exists(@xml:id)" "every section should have an xml:id" ]
  ]]
s:pattern [
  id = "block-level.checks"

  s:title [ "Block Level has xml:id" ]
  s:rule [
    context =
      "db:calloutlist | db:itemizedlist | db:orderedlist |                      db:simplelist | db:variablelist |  db:note |           db:address | db:literallayout |  db:creen |          db:example | db:informalexample | db:figure |          db:informalfigure | db:table |  db:para | db:simpara | db:formalpara |          db:equation | db:informalequation | db:figure |  db:graphic | db:mediaobject |          db:qandaset | db:blockquote |  db:epigraph |  db:highlights |         db:procedure | db:sidebar"

    s:assert [ test = "exists(@xml:id)" "every block-level element should have an xml:id" ]
  ]]
# b) There is a rather loose <s:range> element allowed in the schema.
# Have a look here:
# http://code.google.com/p/dk-schema/source/browse/work-in-progress/ranges/DB-5.0%20mark-up/date.xml
# we need to validate two things again:
# -that for every start of range there is an endofrange
# -that startofrange has xml:id - try to have a general xml:id rule and
# reuse it if possible - in this the endofrange element doesn't have to
# have xml:id so we can't simply add it to the list from a)

s:pattern [
  id = "range.checks"

  s:title [ "Range Checks" ]
  s:rule [
    context = "db:range[matches(@class,'^startofrange$')]"
    s:assert [
      test = "exists(following-sibling::db:range[matches(@class,'^endofrange$')])"
      "for every start of range there should be an range with class=endofrange"
    ]

    s:assert [ test = "exists(@xml:id)" "startofrange should have xml:id" ]
  ]
  #   <s:rule context="db:range[matches(@class,'^startofrange$')]">
  #
  # </s:rule>]
# c) keys: many samples on this in the repo, but the idea is that key
# will always be a variablelist, so check that:
# -varaiblelist and each listentry has xml:id (again only if it's a key
# - normal lists don't always have to ahve xml:ids)
# ** NOT DONE THIS ONE  -if the xref has "keyref_include, it would bee good to see if
# varaiblelist is allowed where xref is, nt sure if it can be done in
# schematron

s:pattern [
.....
        # I put my rules above the first start element.. also tried after it but different syntax error
  ]]

start =    # syntax error here
  set

I read that "RELAX NG allows an annotation to be placed in square brackets immediately preceding the construct to be annotated. " does this mean I can't place them all the patterns in one place like the RNG?

Thanks



On Fri, Feb 3, 2012 at 4:56 PM, Alex Muir <alex.g.muir@gmail.com> wrote:

Thought it a bit interesting that when converting

    <s:pattern id="condition.checks">
      <s:title>Whenever condition attribute is used the element should have have an xml:id or cref
        attribute</s:title>
     
      <s:rule context="*[exists(@condition)]">
        <s:assert test="exists(@cref) or exists(@xml:id)">There should be an xml:id or cref
          attribute</s:assert>
      </s:rule>
    </s:pattern>



with trang I get this lovely concoction,,




s:pattern [
  id = "condition.checks"
  "\x{a}" ~
  "      "
  s:title [
    "Whenever condition attribute is used the element should have have an xml:id or cref\x{a}" ~
    "        attribute"
  ]
  "\x{a}" ~
  "      \x{a}" ~
  "      "
  s:rule [
    context = "*[exists(@condition)]"
    "\x{a}" ~
    "        "
    s:assert [
      test = "exists(@cref) or exists(@xml:id)"
      "There should be an xml:id or cref\x{a}" ~
      "          attribute"
    ]
    "\x{a}" ~
    "      "
  ]
  "\x{a}" ~
  "    "
]


I've since formated the rng without as many line breaks below which is a bit better but I gather Trang likes adding escaped newlines \x{A} to the rnc..

this can all be stripped?

  "\x{a}" ~
  "    "

Regex to the rescue? or am I doing something wrong?

thanks



s:pattern [
  id = "condition.checks"
  "\x{a}" ~
  "    "
  s:title [ "Whenever condition attribute is used the element should have have an xml:id or cref attribute" ]
  "\x{a}" ~
  "     "
  s:rule [
    context = "*[exists(@condition)]"
    "\x{a}" ~
    "      "
    s:assert [ test = "exists(@cref) or exists(@xml:id)" "There should be an xml:id or cref attribute" ]
    "\x{a}" ~
    "    "
  ]
  "\x{a}" ~
  "  "
]


On Fri, Feb 3, 2012 at 4:05 PM, John Cowan <cowan@mercury.ccil.org> wrote:
[sch:pattern
 [sch:title "Date rules"]
 [sch:rule context="Contract"
   [sch:assert test="ContractDate < current-date()"
     "ContractDate should be in the past because future contracts are not allowed."]]]

Clunky, but usable.  Trang understands this syntax when converting from
RNG to RNC and vice versa.



--
Alex Muir

Program Organizer - University Technology Student Work Experience Building
University of the Gambia

https://sites.google.com/a/utg.edu.gm/utsweb/

Come visit Gambia enjoy the sun and culture and help out! Software Engineering Lecturers needed!
Join UTSWEB do local contract work or give a student a contract remotely for slow, cheap and good work https://sites.google.com/a/utg.edu.gm/utsweb/

Some fantastic African/Canadian Fusion  http://bafila.bandcamp.com/




--
Alex Muir
Program Organizer - University Technology Student Work Experience Building
University of the Gambia

https://sites.google.com/a/utg.edu.gm/utsweb/

Come visit Gambia enjoy the sun and culture and help out! Software Engineering Lecturers needed!
Join UTSWEB do local contract work or give a student a contract remotely for slow, cheap and good work https://sites.google.com/a/utg.edu.gm/utsweb/

Some fantastic African/Canadian Fusion  http://bafila.bandcamp.com/



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.