Using two elements for xsl: key key

I know that if I have an XML file, for example:

 <persons>
   <class name="English">
        <person name="Tarzan" id="050676"/>
        <person name="Donald" id="070754"/>
        <person name="Dolly" id="231256"/>
   </class>
   <class name="Math">
        <person name="Winston" id="050677"/>
        <person name="Donald"  id="070754"/>
        <person name="Fred"    id="231257"/>
   </class>
 </persons>

I can define the key in the XSL file as follows:

 <xsl:key name="preg" match="person" use="@id"/> 

where i use id as a key. However, Donald is listed twice, but only in one place in the preg.

Suppose I want it to be listed twice in preg. That is, I want the class name to be part of the identifier. Basically, I want preg to have keys equivalent to ordered pairs: (class-name, id). How to do it (using XSLT 1.0)?

+3
source share
1 answer

Combine keys? What about

use="concat(../@name, @id)"

. , . - , , ,

use="concat(../@name, '|', @id)"

Michael Kay XSLT2.

+6

Source: https://habr.com/ru/post/1756599/


All Articles