View Single Post
  #1 (permalink)  
Old Sep 6th, 2006, 02:20
VmusicV VmusicV is offline
New Member
Join Date: Sep 2006
Location: Columbus, OH
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
xsl - how to retrieve IDREF data?

Hi,
I have an xml document that contains a list of events and uses ID and IDREF to normalize people or persons. So one person could be involved in two different events and they are referenced through IDREF.

have the xml document and xsd shown below.

I would like to use xsl to denormalize this and display the list or collection of events with the person's data (basically name) brought into the event. If one person is involved in multiple events then their data would displayed multiple times.


How could I do this with xsl?


Thanks!!
VmusicV

The xml document is first and then the schema
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="some_folder\foreign-key.xsd">
    <event>
        <start-date>2022-10-01</start-date>
        <end-date>2022-10-01</end-date>
        <event-type>birth</event-type>
        <event-id>EID0001</event-id>
        <event-people role-type="father">ID0001</event-people>
        <event-people role-type="mother">ID0002</event-people>       
        <location></location>
    </event>
    <event>
        <start-date>2005-08-12</start-date>
        <end-date>2005-08-12</end-date>
        <event-type>birth</event-type>
        <event-id>EID0002</event-id>
        <event-people role-type="self">ID0001</event-people>
        <event-people role-type="attendee">ID0002</event-people>       
        <event-people role-type="attendee">ID0006</event-people>       
        <location></location>
    </event>   
    <persons>
        <person>
            <person-name name-type="first">Bill</person-name>
            <person-name name-type="last">Walters</person-name>           
            <person-id>ID0001</person-id>
        </person>

        <person>
            <person-name name-type="first">Jane</person-name>
            <person-name name-type="last">Walters</person-name>           
            <person-id>ID0002</person-id>
        </person>   
        <person>
            <person-name name-type="first">George</person-name>
            <person-name name-type="last">Johnson</person-name>           
            <person-id>ID0003</person-id>
        </person>       
        <person>
            <person-name name-type="first">Jim</person-name>
            <person-name name-type="last">Kaminski</person-name>           
            <person-id>ID0004</person-id>
        </person>
        <person>
            <person-name name-type="first">Sally</person-name>
            <person-name name-type="last">Smith</person-name>           
            <person-id>ID0005</person-id>
        </person>
        <person>
            <person-name name-type="first">Alex</person-name>
            <person-name name-type="last">Hernandez</person-name>           
            <person-id>ID0006</person-id>
        </person>                           
    </persons>
</events>
and the xsd or schema
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="events">
           <xs:complexType>
            <xs:sequence>
                <xs:element name="event" type="event" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element name="persons">
                   <xs:complexType>
                        <xs:sequence>
                            <xs:element name="person" type="person" maxOccurs="unbounded"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="person-name">
         <xs:complexType>
            <xs:sequence>
                <xs:element name="name-type">
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:enumeration value="last"/>
                            <xs:enumeration value="first"/>
                            <xs:enumeration value="middle"/>
                            <xs:enumeration value="nick"/>
                            <xs:enumeration value="alias"/>
                            <xs:enumeration value="full"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:element>
                <xs:element name="name-text"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="person">
        <xs:annotation>
            <xs:documentation>An individual human</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="person-name" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:string">
                            <xs:attribute name="name-type" use="required">
                                <xs:simpleType>
                                    <xs:restriction base="xs:string">
                                        <xs:enumeration value="first"/>
                                        <xs:enumeration value="last"/>
                                        <xs:enumeration value="middle"/>
                                        <xs:enumeration value="maiden"/>
                                    </xs:restriction>
                                </xs:simpleType>
                            </xs:attribute>
                        </xs:extension>
                    </xs:simpleContent>
                </xs:complexType>
            </xs:element>
            <xs:element name="person-id" type="xs:ID"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="event">
        <xs:annotation>
            <xs:documentation>A planned or unplanned activity that people are involved in </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="start-date" type="xs:date"/>
            <xs:element name="end-date" type="xs:date"/>
            <xs:element name="event-type">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="school graduation"/>
                        <xs:enumeration value="school attendance"/>
                        <xs:enumeration value="military service"/>
                        <xs:enumeration value="death"/>
                        <xs:enumeration value="birth"/>
                        <xs:enumeration value="baptisim"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element name="event-description" type="xs:string" minOccurs="0"/>
            <xs:element name="event-id" type="xs:ID"/>
            <xs:element name="event-people" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:IDREF">
                            <xs:attribute name="role-type" use="required">
                                <xs:simpleType>
                                    <xs:restriction base="xs:string">
                                        <xs:enumeration value="father"/>
                                        <xs:enumeration value="doctor"/>
                                        <xs:enumeration value="pastor"/>
                                        <xs:enumeration value="mother"/>
                                        <xs:enumeration value="self"/>
                                        <xs:enumeration value="planner"/>
                                        <xs:enumeration value="attendee"/>
                                        <xs:enumeration value="member"/>
                                    </xs:restriction>
                                </xs:simpleType>
                            </xs:attribute>
                        </xs:extension>
                    </xs:simpleContent>
                </xs:complexType>
            </xs:element>
            <xs:element name="location" type="location"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="location">
        <xs:annotation>
            <xs:documentation>A general or specific geographic place</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="location-name" minOccurs="0"/>
            <xs:element name="address-line-1" minOccurs="0"/>
            <xs:element name="address-line-2" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="country">
        <xs:annotation>
            <xs:documentation>A country of the planet earth</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="name"/>
            <xs:element name="iso-country-code">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="AF"/>
                        <!-- and others -->
                      </xs:restriction>
                </xs:simpleType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="US-State">
        <xs:sequence>
            <xs:element name="state-abbreviation">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="AL"/>
                        <!-- and others -->
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element name="state-name"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>
Reply With Quote