XPATH query with XML and XSD

Questions about XML that are not covered by the other forums should go here.
tobi9595
Posts: 4
Joined: Fri Dec 13, 2019 1:32 am

XPATH query with XML and XSD

Post by tobi9595 »

Hello together, I´ve got the following problem:

As you can see in the following code, I´ve made an studyadministration, in which every study has an ID, that linked to the course of study.

Part of XML-File (Art --> Dual):

Code: Select all

 <Studiengänge>
        <StudiengangID>S01</StudiengangID>
        <studiengang>Wirtschaft</studiengang>
        <charakteristik>Bachelor</charakteristik>
        <art>Dual</art>
        <Fakultät>F1</Fakultät>
    </Studiengänge>

Code: Select all

<student>
        <name>Mustermann</name>
        <vorname>Lukas-Meyer</vorname>
        <matrikelnummer>m502368</matrikelnummer>
        <aktuelleHochschule>AH01</aktuelleHochschule>
        <StudiengangID>S01</StudiengangID>
        <studiumart>Vollzeitstudium</studiumart>
        <amStudieren>Nein</amStudieren>
        <studienbeginn>2016-03-02</studienbeginn>
        <studienende>
            <Datum>2019-03-02</Datum>
            <Grund>Eigener Wunsch</Grund>
        </studienende>
        <postadresse>
            <vorname>Test</vorname>
            <name>Testermann</name>
            <straße>Hausstraße</straße>
            <hausnummer>11</hausnummer>
            <postleitzahl>345678</postleitzahl>
            <ort>testort</ort>
            <land>DE</land>
        </postadresse>
        <email>well-formed@web.de</email>
        <auslandssemester>
            <status>laufend</status>
            <HochschulID>H01</HochschulID>
        </auslandssemester>
    </student>
Part of .xsd-File:

Code: Select all

<xs:element name="studentenverwaltung" type="studentenverwaltungsTyp"/>

    <xs:complexType name="studiengängetyp">
        <xs:sequence>
            <xs:element name="StudiengangID" type="xs:ID" maxOccurs="unbounded"/>
            <xs:element name="studiengang" type="studiengangstyp" maxOccurs="unbounded"/>
            <xs:element name="charakteristik" type="charakteristikTyp" maxOccurs="unbounded"/>
            <xs:element name="art" type="artType" maxOccurs="unbounded"/>
            <xs:element name="Fakultät" type="xs:IDREF" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

<xs:complexType name="studentenverwaltungsTyp">
        <xs:sequence>
            <xs:element name="Studiengänge" type="studiengängetyp" maxOccurs="unbounded"/>
            <xs:element name="Fakultäten" type="fakultätenTyp" maxOccurs="unbounded"/>
            <xs:element name="AuslandsHochschulen" type="auslandshochschulenType" maxOccurs="unbounded"/>
            <xs:element name="aktuellehochschule" type="aktuelleHochschule" maxOccurs="unbounded"/>
            <xs:element name="student" type="studentTyp" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="studentTyp">
        <xs:sequence>
            <xs:element name="name" type="namenTyp" minOccurs="1"/>
            <xs:element name="vorname" type="namenTyp" minOccurs="0"/>
            <xs:element name="matrikelnummer" type="matrikelnummerTyp" minOccurs="1"/>
            <xs:element name="aktuelleHochschule" type="xs:IDREF" maxOccurs="1"/>
            <xs:element name="StudiengangID" type="xs:IDREF"/>
            <xs:element name="studiumart" type="studiumartTyp" minOccurs="1"/>
            <xs:element name="amStudieren" type="amStudierenTyp"/>
            <xs:element name="studienbeginn" type="datumTyp" minOccurs="1"/>
            <xs:element name="studienende" type="studienendeTyp" minOccurs="0"/>
            <xs:element name="postadresse" type="postadressenTyp" minOccurs="1"/>
            <xs:element name="email" type="emailTyp" minOccurs="1"/>
            <xs:element name="zusatzMail" type="emailTyp" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="auslandssemester" type="auslandssemesterTyp"/>
        </xs:sequence>
    </xs:complexType>
I´m new to the hole topic, and worked only with elements.
How is it possible by Xpath-querys, to ask how many students are in an study-course, that is "dual"?
So that I can access the ID-data from the associated IDREF-data.

Best regards,
Tobias!
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: XPATH query with XML and XSD

Post by adrian »

Hi,

The XPath would look like this:

Code: Select all

count(//student[StudiengangID=//Studiengänge[art='Dual']/StudiengangID])
This counts all students that are in all study courses that are Dual. If you want a specific one, or if you want a per study count, you need more complex code. So which one is it?

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
tobi9595
Posts: 4
Joined: Fri Dec 13, 2019 1:32 am

Re: XPATH query with XML and XSD

Post by tobi9595 »

adrian wrote: Fri Dec 13, 2019 1:24 pm Hi,

The XPath would look like this:

Code: Select all

count(//student[StudiengangID=//Studiengänge[art='Dual']/StudiengangID])
This counts all students that are in all study courses that are Dual. If you want a specific one, or if you want a per study count, you need more complex code. So which one is it?

Regards,
Adrian
Hi Adrian,

many thanks to you, this is exactly what I was searching for!

Best regards,
Tobias!
Post Reply