This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: DTD help!


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]