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

Re: DTD help!

Subject: Re: DTD help!
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 10 Apr 2001 21:58:38 +0100
howto xml dtd id attribute
Hi Rajesh,

> keeping in the mind that i have to make sure all my session elements
> have to different, is there any way to get around this?

Well, twisting the question so that it's actually relevant to the
group (i.e. about XSLT), you can test within XSLT whether there is
more than one element with a particular id attribute, even if that
attribute isn't (recognised as) an ID attribute.

You can define a key to index the Session elements by their id
attribute. XSLT doesn't care what kind of value the id attribute has
(it's the validating XML parser that the XSLT processor uses that
will).  So you can make the id attribute a CDATA attribute, as David
said, and then use it with a key:

<xsl:key name="Sessions" match="Session" use="@id" />

Then, if you have a list of the ids (which you can get by going
through all the Session elements in the document and retrieving their
ids), you can see whether the key returns more than one Session with
that id.

You can get all the Session ids with //Session/@id (although there may
well be a more efficient path - you don't say what your source looks
like).

Then you can iterate over them and test whether there's more than one
Session with that id:

  <xsl:for-each select="//Session/@id">
     <xsl:if test="key('Sessions', .)[2]">
        <xsl:message terminate="yes">
           ERROR: There is more than one Session with the same id.
        </xsl:message>
     </xsl:if>
  </xsl:for-each>

There are also schema languages that will allow you to test for
uniqueness with values that aren't ID attributes, including XML Schema
and Schematron.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

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
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.