Find the answer to your Linux question:
Results 1 to 2 of 2
Hello, I have several xml files which I would like to transform which are located in a single directory. I use same xslt to transform all files and I would ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2005
    Location
    Helsinki, Finland
    Posts
    7

    Multiple Transformations using XSLTPROC


    Hello,
    I have several xml files which I would like to transform which are located in a single directory. I use same xslt to transform all files and I would like to create a new file from each transformation.. { I would prefer to have same name as old but a little bit different for later references}

    Currently, I am doing this
    Code:
    #!/bin/bash
    XML_FILES_IN_DIRECTORY="xmlFiles.txt"
    XSLT_TRANSFORMER="transformer.xslt"
    
    ls "file"*.xml > "$XML_FILES_IN_DIRECTORY"
    
    while read -r line
    do
    	xsltproc $XSLT_TRANSFORMER $line > ${line%.*}"_sql.xml"
    done < "$XML_FILES_IN_DIRECTORY"
    The above code is inefficient because calling new xsltproc $XSLT_TRANSFORMER is expensive.. Hence above code is inefficient.

    I believe something better.. I am thinking something like this
    Code:
    ls  *.xml  |  xargs -n1 -I {}  /bin/xsltproc  transformer.xslt {} > foo.xml
    But I am stuck because I can't create an output similar to previous code.

    Please kindly help me to achieve my goal.

    Kind Regards,
    Noel Alex Makumuli

  2. #2
    Just Joined!
    Join Date
    Apr 2005
    Location
    Helsinki, Finland
    Posts
    7
    Hello,
    Just to answer myself.. and for the benefit of others should they need it..

    Code:
    ls *.xml | xargs -n1 -I {} sh -c '/bin/xsltproc transformer.xslt "{}" > _{}'
    Did the magic..

    Kind Regards,
    Noel Alex Makumuli

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •