0

I have a xml document in which i have used IDs and IDREFs in the hope that they could be connected in xlst using xpath, but I haven't been able to find a solution as to how. My xml goes like this:

<root>
  <list>
    <item id="c1"> <description> Class 1 </description> </item>
    <item id="gc1"> <description> Gym-class 1 </description> </item>
    <item id="c2"> <description> Class 2 </description> </item>
  </list>

  <school name="abc">
     <schedule>
       <class idref="c1">
         <day>monday</day>
         <day>friday</day>
       </class>
     </schedule>
  </school>
  <school name="def">
     <schedule>
       <class idref="gc1">
         <day>tuesday</day>
         <day>thurday</day>
       </class>
     </schedule>
  </school>
</root>

And I wanted to make a connection in a way that on the output (which is html) when I reference the value in idref, what shows up would be the description in the list, in the beggining. Is this even possible?

1 Answers1

0

Yes. It is easily possible. But the output depends on your XPath-version.
The following XPath-expression

/root/list/item[@id=/root/school/schedule/class/@idref]/description

returns the first item in XPath-1.0 and a set of nodes in XPath-2.0 and above.
So the output is either (without any special concatenation applied)

  1. Class 1 (1.0)
  2. Class 1 Gym-class 1 which returns all items fulfilling the requirements (2.0+).

If you want to get a certain <item>'s description, you should replace the /root/school/schedule/class/@idref in the expression above with the idref value you want to retrieve from the <item> list..

zx485
  • 28,498
  • 28
  • 50
  • 59
  • So I have no way of making the description correspond only to the id referenced automaticallt, I would have to specify the idref everytime? Anyway, thank you, it already helped a lot – rita pena Dec 09 '21 at 15:57