BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


Schemas, xsd, xdr
Entity name support without DTDs
The Loss of Formatting When Adding a Schema
simple xml notepad
Schemas using DBMS_XMLQuery Package
Tips for Designing a DTD - Part 1 of 4
Tips for Designing a DTD- Part 2 of 4 : Semi-Structured Documents
Tips for Designing a DTD- Part 3 of 4 : Database Oriented Data
Tips for Designing a DTD- Part 4 of 4 : Object Oriented Data
Getting the value of an element with optional subelements
XML Code Generator: Generating Wrapper Classes from an XML Schema
What is WDDX?
XSLT Stylesheet for summarizing the structure of an XML document
Validating XML with Schemas
Punctuated Changes In XML Documents
XMLStarlet Command Line XML Toolkit
W2XML v2.0 SR1
Free DTD for Academic Publishers
Arquemie for XML Schemas
XMLStarlet Command Line XML/XSLT Toolkit
XSD Merger


 
 

<< reBloggerSEO >>


By Dimitre Novatchev
First Posted 03/27/2001
Times viewed 310

Validating and enforcing a list of attribute values


Summary This snippet presents a method of validating if a list of names (specified as an atrribute value) contains names from a given "approved" list of values. Categories: XSLT, DTD, id() function, validation.

This problem was raised by Peter Flynn in the XSLT mailing list (http://sources.redhat.com/ml/xsl-list/2001-02/msg00215.html): Imagine letting students specify the options (actually allowed stylesheet names) for printing their thesis. A student will have specified these as: " where foo.sty, bar.sty, and blort.sty are among the allowed options(ie declared entities in the DTD) for translation to LaTeX's \usepackage{foo,bar,blort}. Just a safety check to make sure a student doesn't go haywire." We want to allow foo.sty and bar.sty, but to discard blort.sty The idea for the solution is to use the id() function. The actual implementation (first presented by Jeni Tennison) has since then been put into the XSLT FAQ site of Dave Pawson (http://dpawson.co.uk/xsl/muench.html#N38692) It doesn't involve recursive templates, as long as one doesn't mind repeating in the stylesheet the list of allowed options. It has the advantage that one can deal with bad values (e.g. if 'blort' wasn't actually allowed) within the stylesheet. When applied on the following xml source document: The xsl stylesheet below will produce the following result: Options: foo, bar There are some interesting things to note about this solution: 1. In order to use the id() function, an attribute must be defined as ID in the DTD. 2. To make it independent from any particular xml source document, the element having an ID - type attribute is made part of the stylesheet. 3. Because of the previous two considerations the stylesheet must have its own DTD describing the ID - typed attribute. 4. In order to get the id() function select nodes from the stylesheet, the stylesheet must be made the current document. This is achieved by the following: 5. This solution has been tested to work successfully with the SAXON xslt processor. To summarise, this is a general method for validating and enforcing a list of allowed names as values of an attribute.

Additional information

Further additional information


Rate this article on a scale of 1 to 10 (0 votes, average 0)

Your vote :  

<< reBloggerSEO >>





Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML