Custom Output File Name in XSLT Transformation Scenarios

Having trouble installing Oxygen? Got a bug to report? Post it all here.
sarcanon
Posts: 39
Joined: Mon Aug 24, 2009 11:42 pm

Custom Output File Name in XSLT Transformation Scenarios

Post by sarcanon »

There must be a way to do this, but after spending almost an hour reviewing the docs and this forum, I cannot find it.

I would like to define the output file name in an XSLT Transformation Scenario using content from within the XML document currently being transformed. I've carefully reviewed all of the Editor Variables available, but they all seem to reference information external to the XML document, mostly file paths and file system information. I've also looked at Custom Editor variables, but insofar as I can tell this functionality only allows the definition of static values. There are ways to reference environment and Java system variables, but, again, these are all external to the file being transformed.

Ideally, I would like to access a processing instruction or provide an XPath to an element within the file that I could use to construct the output file name.

Is this sort of thing possible?

Thank you in advance.
adrian
Posts: 2850
Joined: Tue May 17, 2005 4:01 pm

Re: Custom Output File Name in XSLT Transformation Scenarios

Post by adrian »

Hello,

I'm afraid that's not possible, at least not for the main output file specified in the transformation scenario. The output is specified for the transformer/engine at the moment the transformation starts, so you can't make it dynamic depending on the content.

However, assuming you're using XSLT 2.0, why not use xsl:result-document in your stylesheet?
e.g.

Code: Select all

<xsl:result-document href="file{element/id}.xml">
...
</xsl:result-document>
This xsl:result-document block will output to a file named: fileN.xml where N is has the value of the XPath expression element/id.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
sarcanon
Posts: 39
Joined: Mon Aug 24, 2009 11:42 pm

Re: Custom Output File Name in XSLT Transformation Scenarios

Post by sarcanon »

So, use xsl:result-document in lieu of the Save As action in the transformation scenario?

That seems like a perfectly satisfactory solution.

Thank you.
Rumplestiltzkin
Posts: 28
Joined: Thu Mar 12, 2009 4:16 am

Re: Custom Output File Name in XSLT Transformation Scenarios

Post by Rumplestiltzkin »

Just wondering if anything has changed in this respect in the last 5 years? I would _really_ like to be able to have output file names from an XSL transformation that vary according to content. There are reasons why I can't really use xsl:result-document, so if the output naming functionality in XSLT Transformation Scenarios has improved, I'd love to find out about it.
Rumplestiltzkin
Posts: 28
Joined: Thu Mar 12, 2009 4:16 am

Re: Custom Output File Name in XSLT Transformation Scenarios

Post by Rumplestiltzkin »

Whoops! Sorry; I misread the user join time as the message posting time. :oops: It's not been 5 years; only 1 or so, so the answer, I'm sure is "no."
adrian
Posts: 2850
Joined: Tue May 17, 2005 4:01 pm

Re: Custom Output File Name in XSLT Transformation Scenarios

Post by adrian »

Hi,

Starting with v16.0 there is a new editor variable that can be used to evaluate an XPath directly in the Output/Save As field:

Code: Select all

${xpath_eval(expression)}
So, you can use an XPath expression to contribute to the output file path and name.
e.g.

Code: Select all

${cfd}/${xpath_eval(doc('personal.xml')/personnel[1]/person[1]/@id)}.xml
However, in Windows, due to a bug (present in v16.0 builds, up to 2014052022), you must escape the forward slash characters '/', to avoid the Windows path correction (replaces '/' with'\' and breaks the XPath expression).
So, for the example above, in order to work in Windows, the expression must look like this (replaced '/' with '&#x2f;'):

Code: Select all

${cfd}\${xpath_eval(doc('personal.xml')&#x2f;personnel[1]&#x2f;person[1]&#x2f;@id)}.xml
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Rumplestiltzkin
Posts: 28
Joined: Thu Mar 12, 2009 4:16 am

Re: Custom Output File Name in XSLT Transformation Scenarios

Post by Rumplestiltzkin »

Suite!!! :D :D :D
Post Reply