[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] [XSL] id() in Ancestor Nodes?


Subject: Re: [xsl] [XSL] id() in Ancestor Nodes?
From: George Cristian Bina <george@xxxxxxxxxxxxx>
Date: Thu, 04 Oct 2007 10:12:38 +0300

Two more points in addition to Ken's reply.
You can also use a Schema aware XSLT 2.0 processor like Saxon8 SA with an XML schema that specifies as xs:ID the ID values and you will get the id function working.
The alternative to id is to define and use a key. For instance you can define


<xsl:key name="publicationById" match="publication" use="@xml:id"/>

and replace

id('@publish') (which should have been id(@publish) BTW) with

key('publicationById', @publish)

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina - http://aboutxml.blogspot.com/
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


G. Ken Holman wrote:
At 2007-10-03 23:28 -0400, Alice Ju-Hsuan Wei wrote:
I am trying to use the id function in XSLT to extract the publication id information from the "attribute" and have the output display the name of the publisher itself as it is. The complete code is as follows:

XML:

<bookshelf>

I note there is no DTD declaration of the attribute that has the ID type ... therefore, if you are using XSLT 1.0 you will need:


<!DOCTYPE bookshelf
[
<!ATTLIST publication xml:id ID #IMPLIED>
]>
<bookshelf>

If you are using XSLT 2.0, it is up to your XSLT processor to choose to implicitly support xml:id (ref: 3.11 note), and if it does not, the above is required.

I tried using the id function:

<xsl:template name="bookpublisher">
       <xsl:variable name="name" select="id('@publish')"/>

If the processor is not instructed which attributes of which elements have attributes of type ID (the name is irrelevant; the type is given in a DTD declaration) for a given document, then the id() table is empty for the document.


I hope this helps.

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


-- Upcoming public training: UBL and code lists Oct 1/5; Madrid Spain World-wide corporate, govt. & user group XML, XSL and UBL training RSS feeds: publicly-available developer resources and training 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) Male Cancer Awareness Jul'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal


Current Thread