Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Scenario: I have a project with a number of XML files and I would like to apply a XSLT transform on these and then use that output for other purposes.

There is a variety of tools to do this, but it would be nice to be be able to stay in the editor while debugging/using the transform.

share|improve this question
    
What tools do you use and what system are you on? I ended up making a custom (quite complex) build scripts for knitr and others. – mreq Apr 13 '13 at 20:59
    
I am using a variety of tools and platforms, many of which have XSLT capabilities, so my question was whether there exists a plugin or similar that would smoothly allow me to apply an XSLT transform inside of the editor. External scripts might be OK as long as it is a one-time effort that can later be used on arbitrary XML/XSLT-files. – erikxiv Apr 26 '13 at 12:29
    
If you're able to create a custom bash script, it's easy to run it from sublime. If you're able to, I can link you to some further reading. – mreq Apr 26 '13 at 15:34
1  
I guess one of the tricks is that (1) the script requires two inputs, the xslt and the xml, and (2) that the output is a new file. If I write a script that takes three filenames as input (incl output name), how would I execute that and view the output without leaving the editor? If possible, could you write an answer so I can accept it? – erikxiv Apr 30 '13 at 8:53
up vote 1 down vote accepted

If you have 3 different files you need, you can use first-line (or second if you need utf8 stuff) comments. I use it to compile the main TeX file from one of the children.

%!../main_file.tex
\documentclass[12pt,a4paper]{scrartcl}

\usepackage[czech,english]{babel}

I have a script, which looks at the first line:

match=`head -n1 $1 | grep %!`

if [[ $match ]]
    then
        # do stuff with the parent's name, which is ${match:2:100}
    else
        # no match :/
fi

and a simple build file aiming at my custom script:

{
    "cmd": ["/path/to/build/script.sh", "$file"],
    "selector": "whatever"
}

This way, you can have as many "references" in your files as you want. Just switch the value of head -n1.

In XML, you would probably use <!--%somefilename --> with head -n1 $1 | grep '<!--%' and ${match:5:100}.

To end with, I present to you my XeLaTeX build script ;)

#!/bin/bash
file="$1"
flag="-halt-on-error"

match=`head -n1 $file | grep %!`

if [[ $match ]]
    then
        if [ ${match:2:3} = ../ ]
            then
                cd .. &&
                target=${match:5:100}
            else
                target=${match:2:100}
        fi
    else
        target=$file
fi
rubber -c 'set arguments -shell-escape' -f -m xelatex -W all $target

exit 0
share|improve this answer
    
Smart thinking. During testing of my xslt I just add comments pointing to input/output filenames and then use the build script to execute the xslt. Thanks! – erikxiv May 7 '13 at 13:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .