bash to xproc (unix to XML)

102 Views Asked by At

I am trying to understand how xproc works and to convert bash scripts to xproc.

I am used to bash scripting, but now the idea is to have everything in an XML format...

here is my bash script: It creates some info in arrays and then loops over one of the arrays to write a file using cat.

 #!/bin/bash

 Titel=("Star Wars" "Eraserhead" "Unforgiven")
 Jahr=(1978 1976 1992)
 Genre=("SciFi" "Horror" "Western")
 Regisseur=("George Lucas" "David Lynch" "Clint Eastwood")

 Film=(Titel Jahr Genre Regisseur)

 Datum=()

 echo "${Titel[@]}"
 echo "${Jahr[@]}"
 echo "${Genre[@]}"
 echo "${Regisseur[@]}"
 echo "${Film[@]}"
 echo "${Datum[@]}"

   for j in "${!Jahr[@]}"
   do
    Datum+=(${Jahr[j]})
     cat <<EOF>> Filmsammlung.txt
 ${Titel[j]}
 ${Jahr[j]}
 ${Genre[j]}
 ${Regisseur[j]}

 EOF

 done

And here is the corresponding xproc (I think...)

 <?xml version="1.0" encoding="UTF-8"?>
 <p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0">
    <p:input port="source">
       <p:document href="filmsammlung.xml"/>
    </p:input>
    <p:output port="result" sequence="true"/>
    <p:for-each>
 <!-- this should iterate over Jahr: for j in "${!Jahr[@]}"-->
       <p:iteration-source select="//Jahr"/>
       <p:output port="result"/>
 <!-- do Datum+=(${Jahr[j]}) (I am not renaming my aray, but cheating by creating a new array called Datum...)-->
       <p:rename match="/Jahr" new-name="Datum"/>
 <!-- this executes cat for each iteration..-->
          <p:exec command="cat" result-is-xml="true" name="exec"/>
 <!-- this deals with possible errors...-->
          <p:identity>
             <p:input port="source">
                <p:pipe port="errors" step="exec"/>
             </p:input>
           </p:identity>
           <p:store href="fehler.xml"/>
           <p:identity>
              <p:input port="source">
                 <p:pipe port="exit-status" step="exec"/>
              </p:input>
           </p:identity>
           <p:store href="exit_status.xml"/>
           <p:identity>
              <p:input port="source">
           <p:pipe port="result" step="exec"/>
              </p:input>
           </p:identity>
           <p:store href="resultat.xml"/>
    </p:for-each>
 </p:declare-step>

Does it make sense? I am a complete newbie to xproc - how can I test what xproc is doing?

Filmsammlung.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<FilmSammlung>
  <Film>
    <Titel>Star Wars: Episode IV - A New Hope</Titel>
    <Jahr>1978</Jahr>
    <Genre>SciFi</Genre>
    <Regisseur>George Lucas</Regisseur>
    <Produzent>George Lucas</Produzent>
    <Cast>
      <Hauptdarsteller>Mark Hamill</Hauptdarsteller>
      <Hauptdarsteller>Harrison Ford</Hauptdarsteller>
    </Cast>
    <Laenge>121 min</Laenge>
    <Autor>George Lucas</Autor>
  </Film>
  <Film>
    <Titel>Eraserhead</Titel>
    <Jahr>1976</Jahr>
    <Genre>Horror</Genre>
    <Regisseur>David Lynch</Regisseur>
    <Produzent>David Lynch</Produzent>
    <Cast>
      <Hauptdarsteller>Jack Nance</Hauptdarsteller>
      <Hauptdarsteller>Allen Joseph</Hauptdarsteller>
    </Cast>
    <Laenge>89 min</Laenge>
    <Autor>David Lynch</Autor>
  </Film>
  <Film>
    <Titel>Unforgiven</Titel>
    <Jahr>1992</Jahr>
    <Genre>Western</Genre>
    <Regisseur>Clint Eastwood</Regisseur>
    <Produzent>Clint Eastwood</Produzent>
    <Cast>
      <Hauptdarsteller>Clint Eastwood</Hauptdarsteller>
      <Hauptdarsteller>Gene Hackman</Hauptdarsteller>
    </Cast>
    <Laenge>131 min</Laenge>
    <Autor>David Webb Peoples</Autor>
  </Film>
</FilmSammlung>
0

There are 0 best solutions below