Search code examples
xmlxqueryoxygenxml

XSD query a bunch of different files


I got three XML files. The first, called plans.xml, include a list of "plan" elements which refer to individual files.

plans.xml:

<plans>
     <plan XSD-version="2.0" release="R1801.1" plan-file="./plan-2.0.xml"/>
     <plan XSD-version="3.0" release="R1801.2" plan-file="./plan-3.0.xml"/>
</plans>

Second file, called "plan-2.0.xml" (and third file is similar, just with other version numbers and Name "plan-3.0.xml"):

plan-2-0.xml:

<Services>    
    <service name="x" version="2.0"/>
    <service name="y" version="2.0"/>
    <service name="z" version="2.0"/>
 </Services>

What I want to achieve is an xquery (3.0) that takes an Input parameter (I1801.2) and generates a simple html list with a Header:

<h1>I1801.2</h1>
  <ul>
    <li>x with version 2.0
    <li>y with version 2.0
    <li>z with version 2.0 
  </ul>

I am struggeling with the concrete concepts - it has been more than ten years I used xquery.

my script starts like:

xquery version "3.0";
let $j := doc("plans.xml")

However, I am stuck here. Any help?

More precisely, how to loop through different files, collect elements and attributes into variables and then output them? I am using Oxygen XML as editor.


Solution

  • Can't quite see where XSD comes into it?

    Try:

    for $p in $j//plan
    return (
       <h1>{string($p/@release)}</h1>,
       <ul>{for $s in doc($p/@plan-file//service
            return <li>{string($s/@name} with version {string($s/@version)}</li>
       </ul>)