0

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.

Walter Kuhn
  • 479
  • 1
  • 6
  • 19
  • You have one answer from Michael Kay based on the information you gave. But the title speaks of XSD. If his answer does not suffice, I suggest you update your question with (1) an explanation of where XSD is relevant and (2) a sample output document based on your sample input documents.. – David Ennis -CleverLlamas.com Dec 12 '17 at 08:38

1 Answers1

0

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>)
Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Thanks for your help.in fact I need to organize planning elements for proper processing of many XSDs in various versions. So the XSD-Version tells me, for a certrain plan (= a bunch of versioned XSDs), we have an overall label – Walter Kuhn Dec 14 '17 at 12:41