You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Enric Jaen <en...@nmg.upc.es> on 2006/02/28 15:57:31 UTC

how to select elements with IDREF?

Hi,
 Could someone give me a clue about how to use the idref  attribute to select an element?

For example, in the following document:

<Company>
  <Departments>
    <Department id="d1">
      <Name>Enterprise Development</Name>
    </Department>
    <Department id="d2">
      <Name>Foundation Services</Name>
    </Department>
  </Departments>
  <Employees>
    <Employee DepartmentRef="d1">
      <Name>Jeff</Name>
    </Employee>
    <Employee DepartmentRef="d1">
      <Name>Mike</Name>
    </Employee>
   <Employee DepartmentRef="d2">
     <Name>Sam</Name>
   </Employee>
  </Employees>
</Company>

I'd like to obtain the Department name of Employee Jeff. How can this be done?

I guess I have to use the id() function, but I don't manage to solve this.

Any help will be appreciated.
Regards,
-Enric


Re: how to select elements with IDREF?

Posted by Santiago Pericas-Geertsen <Sa...@Sun.COM>.
On Feb 28, 2006, at 2:56 PM, Enric Jaen wrote:

> Thank you Santiago,
>
> If the id attribute was defined in the DTD as an ID, would it be  
> possible to evaluate it using only XPath (without XSLT) ?

  Yes, I think in that case you can use the id() function as follows:

   id(//Employee[Name='Jeff']/@DepartmentRef)

  Thanks.

-- Santiago

> On Tue, 28 Feb 2006, Santiago Pericas-Geertsen wrote:
>
>> Hi Enric,
>>
>>   An attribute is not of type ID unless it is defined to be so in the
>> DTD. I.e., it does not suffice to name it "id" as in the example
>> below. However, you can solve this problem using xsl:key and key() as
>> follows:
>>
>>   1) Define a key in your stylesheet:
>>
>>   <xsl:key name="departments" match="Department" use="@id"/>
>>
>>   2) The following XPath should then evaluate to a nodeset with the
>> Department element in it:
>>
>>   key('departments', //Employee[Name='Jeff']/@DepartmentRef)
>>
>>   Hope this helps.
>>
>> -- Santiago
>>
>> On Feb 28, 2006, at 9:57 AM, Enric Jaen wrote:
>>
>>> Hi,
>>>  Could someone give me a clue about how to use the idref  attribute
>>> to select an element?
>>>
>>> For example, in the following document:
>>>
>>> <Company>
>>>   <Departments>
>>>     <Department id="d1">
>>>       <Name>Enterprise Development</Name>
>>>     </Department>
>>>     <Department id="d2">
>>>       <Name>Foundation Services</Name>
>>>     </Department>
>>>   </Departments>
>>>   <Employees>
>>>     <Employee DepartmentRef="d1">
>>>       <Name>Jeff</Name>
>>>     </Employee>
>>>     <Employee DepartmentRef="d1">
>>>       <Name>Mike</Name>
>>>     </Employee>
>>>    <Employee DepartmentRef="d2">
>>>      <Name>Sam</Name>
>>>    </Employee>
>>>   </Employees>
>>> </Company>
>>>
>>> I'd like to obtain the Department name of Employee Jeff. How can
>>> this be done?
>>>
>>> I guess I have to use the id() function, but I don't manage to
>>> solve this.
>>>
>>> Any help will be appreciated.
>>> Regards,
>>> -Enric
>>>
>>
>>
>>
>


Re: how to select elements with IDREF?

Posted by Enric Jaen <en...@nmg.upc.es>.
Thank you Santiago,

If the id attribute was defined in the DTD as an ID, would it be possible to evaluate it using only XPath (without XSLT) ?

Thanks for your help,
Regards,

-Enric


On Tue, 28 Feb 2006, Santiago Pericas-Geertsen wrote:

> Hi Enric,
>
>   An attribute is not of type ID unless it is defined to be so in the
> DTD. I.e., it does not suffice to name it "id" as in the example
> below. However, you can solve this problem using xsl:key and key() as
> follows:
>
>   1) Define a key in your stylesheet:
>
>   <xsl:key name="departments" match="Department" use="@id"/>
>
>   2) The following XPath should then evaluate to a nodeset with the
> Department element in it:
>
>   key('departments', //Employee[Name='Jeff']/@DepartmentRef)
>
>   Hope this helps.
>
> -- Santiago
>
> On Feb 28, 2006, at 9:57 AM, Enric Jaen wrote:
>
> > Hi,
> >  Could someone give me a clue about how to use the idref  attribute
> > to select an element?
> >
> > For example, in the following document:
> >
> > <Company>
> >   <Departments>
> >     <Department id="d1">
> >       <Name>Enterprise Development</Name>
> >     </Department>
> >     <Department id="d2">
> >       <Name>Foundation Services</Name>
> >     </Department>
> >   </Departments>
> >   <Employees>
> >     <Employee DepartmentRef="d1">
> >       <Name>Jeff</Name>
> >     </Employee>
> >     <Employee DepartmentRef="d1">
> >       <Name>Mike</Name>
> >     </Employee>
> >    <Employee DepartmentRef="d2">
> >      <Name>Sam</Name>
> >    </Employee>
> >   </Employees>
> > </Company>
> >
> > I'd like to obtain the Department name of Employee Jeff. How can
> > this be done?
> >
> > I guess I have to use the id() function, but I don't manage to
> > solve this.
> >
> > Any help will be appreciated.
> > Regards,
> > -Enric
> >
>
>
>


Re: how to select elements with IDREF?

Posted by Santiago Pericas-Geertsen <Sa...@Sun.COM>.
Hi Enric,

  An attribute is not of type ID unless it is defined to be so in the  
DTD. I.e., it does not suffice to name it "id" as in the example  
below. However, you can solve this problem using xsl:key and key() as  
follows:

  1) Define a key in your stylesheet:

  <xsl:key name="departments" match="Department" use="@id"/>

  2) The following XPath should then evaluate to a nodeset with the  
Department element in it:

  key('departments', //Employee[Name='Jeff']/@DepartmentRef)

  Hope this helps.

-- Santiago

On Feb 28, 2006, at 9:57 AM, Enric Jaen wrote:

> Hi,
>  Could someone give me a clue about how to use the idref  attribute  
> to select an element?
>
> For example, in the following document:
>
> <Company>
>   <Departments>
>     <Department id="d1">
>       <Name>Enterprise Development</Name>
>     </Department>
>     <Department id="d2">
>       <Name>Foundation Services</Name>
>     </Department>
>   </Departments>
>   <Employees>
>     <Employee DepartmentRef="d1">
>       <Name>Jeff</Name>
>     </Employee>
>     <Employee DepartmentRef="d1">
>       <Name>Mike</Name>
>     </Employee>
>    <Employee DepartmentRef="d2">
>      <Name>Sam</Name>
>    </Employee>
>   </Employees>
> </Company>
>
> I'd like to obtain the Department name of Employee Jeff. How can  
> this be done?
>
> I guess I have to use the id() function, but I don't manage to  
> solve this.
>
> Any help will be appreciated.
> Regards,
> -Enric
>