[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|