4

I have been trying to figure out a way to batch transform files in directory using an xslt. I tried xml wrench and a few other software but i need to put all this in a script or batch that i can run as needed.

I have started out with a batch file using raptorxml command line as below:

C:\Program Files (x86)\Altova\RaptorXMLServer2013\bin>RaptorXML.exe xslt --input=c:\data\test1.xml --output=c:\data\output1.xml c:\data\test.xsl

file:///c:/data/test1.xml: result="OK" xslt-output-files="file:///c:/data/output1.xml"

When I try to put this in a batch file as below, I can not understand a thing of what's going on - can't make out if the script ran or was there any error.. Tried putting ECHO in between but that did not help either. I tried to redirect the output to a log using >log.log but that would just get an echo of each of the lines in the file.. i cant see the value of the variables in the look or how the call to raptorxml is being formed. Any hints or pointers will be helpful - thanks.

Here is my batch file: I run it as batchxform.bat C:\data\ip

cls
call :treeProcess
goto :eof

:treeProcess
cd %1
for %%f in (*.xml) do (
RaptorXML.exe xslt --input=%%f --output=c:\data\op\%%~nf.xml c:\data\test.xsl
)

for /D %%d in (%1) do (
   cd %%d
   call :treeProcess
   cd ..
)

exit /b

After the initial answer/post, I added more logic to call the script from another to process files from all subdirs of the input dirs. Thought of sharing that script here:

ECHO OFF
set _xform=C:\Users\gkalra\Documents\work\Annotation\code\batchxform.cmd
rem call _xform %1
FOR /R %1 %%G in (.) DO (
 Pushd %%G
 Echo now in %%G
 rem dir /b "%%G/*.xml"
 call "%_xform%" %%G
 Popd 
)
Echo "back home"
2
  • 1
    For one you should use pushd and popd instead of cd Commented Oct 14, 2013 at 22:00
  • Yep did that for one.. realized that late. Commented Oct 15, 2013 at 12:39

1 Answer 1

4

Save as batchxform.cmd

Asumes inputDir\ip as source of files, inputDir\op as output directory, and inputDir\test.xls as xls

Call as batchxform.cmd c:\data

@echo off
    setlocal enableextensions

    cls

    if "%~1"=="" goto endProcess

    set _inputDir=%~1\ip
    set _outputDir=%~1\op
    set _xsl=%~1\test.xsl
    set _raptor=C:\Program Files (x86)\Altova\RaptorXMLServer2013\bin\RaptorXML.exe

    for %%f in ("%_inputDir%\*.xml") do (
        "%_raptor%" xslt --input="%%f" --output="%_outputDir%\%%~nxf"  "%_xsl%"
    )

:endProcess
    endlocal
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks very very much MC ND.. if you don't mind, could you help understand what made your solution work, and what was i doing wrong? is it the path names involved.. i'll try to find out as well..
Your batch file is not really wrong, mine is simple more organized and (using quotes where needed) is prepared for spaces in file/directory names. Your code tries to recurse the initial directory, processing each subdirectory, probably trying to process what it should not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.