XML
  Home arrow XML arrow Page 3 - More Schematron Features
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

More Schematron Features
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-01-22

    Table of Contents:
  • More Schematron Features
  • More on assertions
  • Declaring variables with the let element
  • Phases
  • Diagnostics

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    More Schematron Features - Declaring variables with the let element


    (Page 3 of 5 )

    Another useful and powerful element in Schematron is the let element. Building expressions in Schematron can get complicated, but the let element can, thankfully, make some things easier. It allows named variables to be declared in a schema. Using the let element, the result of an expression can be assigned to a variable, and the variable can then be used in other expressions.

    The let element is easy to use. It has two simple attributes. The first attribute is the name attribute, used to declare the variable's name. The second attribute is the value attribute, used to assign a value to the variable using an expression.

    Consider an XML element representing an e-mail address. Suppose we want to verify that the domain used in the e-mail address is indeed a valid domain. To do this, we would have to extract the domain from the e-mail address. Then, we'd have to perform a number of tests on the domain, such as checking to see if the domain is of appropriate length, checking to see that the characters are valid, and checking to see that a valid top-level domain is being used. In order to perform all these tests, a lot of assertions would have to be made. These assertions would be easier if the domain name could be stored in a variable rather than having to be extracted in each assertion.

    Here's how the domain name could be extracted from an e-mail address contained in an email element using a let element and an XPath expression:


    <let name="domain" value="substring-after(email,'@')"/>


    The let element above would go at the assertion level, though it is possible to use the let element at different levels in the document.

    The domain can now be checked for validity. For example, an entire domain name cannot be longer than 253 characters. The name can easily be checked against this using the variable we just created:


    <report test="string-length($domain)>253">The domain is too long.</report>


    As you can see, variables declared using let are referenced just as parameters are in an abstract pattern.

    More XML Articles
    More By Peyton McCullough


     

    XML ARTICLES

    - Using Regions with XSL Formatting Objects
    - Using XSL Formatting Objects
    - More Schematron Features
    - Schematron Patterns and Validation
    - Using Schematron
    - Datatypes and More in RELAX NG
    - Providing Options in RELAX NG
    - An Introduction to RELAX NG
    - Path, Predicates, and XQuery
    - Using Predicates with XQuery
    - Navigating Input Documents Using Paths
    - XML Basics
    - Introduction to XPath
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek