Re: [xsl] Function id() does not work XSLT - XML - XML-Schema

Subject: Re: [xsl] Function id() does not work XSLT - XML - XML-Schema
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 20 Dec 2002 02:56:16 -0500
At 2002-12-20 08:18 +0100, robhan@xxxxxx wrote:
Question: Why does the Function id() not work??

Because you have not instructed the processor which attributes are of type ID.


Attribute refDim is of type "IDREFS". Attribute id of
 Dimension
 is of type "ID"

You say that in your schema, but XSLT 1.0 predates W3C Schema.


 For me it looks like, that the xsl transformation does not know the
 schema.
 Correct? If yes, why?

Because XSLT 1.0 was released in November 1999 and W3C Schema was released in May 2001. XSLT 1.0 can, therefore, not have known anything about W3C Schema.


At the beginning of your XML file add an appropriate declaration of the attributes you need recognized:

   <!DOCTYPE SpeedTest
   [
   <!ATTLIST Dimension id ID #REQUIRED>
   ]>

You can make them either #REQUIRED or #IMPLIED and you just have one line per element type declaring which attribute is of type ID.

Without such a declaration there is no way for the XSLT processor to know which attributes are of type ID. The name is irrelevant and there are no assumptions on attributes named ID, only on those declared as type ID.

Note that since there are no element content models declared, there is no validation that goes on ... you are just instructing XML processors which attributes are of type ID.

An alternative would be to use keys instead of ID, but there is no tokenized access to a list of key values so you cannot readily mimic IDREFS. If you are only using IDREF then you don't have to change your XML and you can just have your stylesheet worry about it.

I hope this helps.

................... Ken


-- Upcoming hands-on in-depth XSLT/XPath and/or XSL-FO: - North America: Feb 3 - Feb 7,2003

G. Ken Holman               mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.        http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0  +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                     Definitive XSLT and XPath
ISBN 0-13-140374-5                             Definitive XSL-FO
ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
ISBN 1-894049-10-1             Practical Formatting Using XSL-FO
Next conference training:                          2003-03-03,06


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



Current Thread