problems with transformation scenarios

Here should go questions about transforming XML with XSLT and FOP.
bds
Posts: 47
Joined: Mon Jun 26, 2006 10:40 pm

problems with transformation scenarios

Post by bds »

Hi all -
I've been struggling with applying a transformation scenario - after searching this forum & attempting some of the suggestions I'm still having difficulties.

I have a directory of XML and an XSLT in a second directory:
/Users/me/file/path/XML/*.xml
/Users/me/file/path/XSL/myStyleSheet.xsl

I'd like to set up a transformation scenario, applying the XSL to the *.xml files but can't seem to get it working; I suspect I'm confused about proper usage of the Editor Variables. I've tried this multiple ways: all xml & XSL files in the same directory, separate directories, and I've tried using a Project Scenario, too.

So:
1) under Configure Transformation Scenarios, I select XML transformation with XSLT
2) I give it a name: dcTransform1
3) The *.xml files are all in the same directory, so it seems like I should use ${cfdu} -- otherwise I could use the absolute file path (/Users/me/file/path/XML/) but I'm not quite sure how to declare the *.xml file names (there are ~100 files).
4) The *.xsl URL is easier :)
5) When I select the Output tab, I am using the Save As option -- and I've tried to use ${cfd}, but still no results.

Thanks very much for your time -- any suggestions or advice are greatly appreciated.
Cheers,
Bridger
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: problems with transformation scenarios

Post by adrian »

Hello,

If you have a common XSL file that you need to apply to several XML files then you are on the right track, you should create a scenario of the "XML transformation with XSLT" type.

You can either:
- open one XML file and from the main menu invoke Document -> Transformation -> Configure Transformation Scenario(there's a corresponding action in the toolbar)
- add the XML files to the project, right click on one of them in the Project view and from the contextual menu choose Configure Transformation Scenario.

Further on, make sure the scenario type is "XML transformation with XSLT" and click 'New' to create a new scenario:
1. Give it an appropriate name
2. Leave the 'XML URL' field to its default(${currentFileURL})
3. In the XSL URL field browse for your stylesheet.
4. If you have an XSLT 2.0 stylesheet choose from the transformer combo Saxon-PE, otherwise you can leave it to Saxon6.5.5.
5. You can further tune the 'Output'. e.g in the 'Save as' field you can specify: ${cfd}/${cfn}-out.xml which translates into <current-file-directory>/<current-filename>-out.xml
The "Save as" field must refer a single file, NOT an output directory.
6. OK in all dialogs.

To apply this scenario to several XML files first add them to your project, select them in the Project view and from the contextual menu(right click) choose either:
- "Transform with...", then select your scenario from the list and press 'Transform now'
- Configure Transformation Scenario and select your scenario from the list and press 'Transform now'. This will also associate the scenario with the selected files so next time you can simply use "Apply Transformation Scenario" and the associated scenario will be used.

The transformation scenario will be applied by Oxygen separately for each XML file. This is why the output of the transformation scenario must refer a single file.

Let me know if you need additional assistance.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
bds
Posts: 47
Joined: Mon Jun 26, 2006 10:40 pm

Re: problems with transformation scenarios

Post by bds »

Hi all -
apologies for resurrecting a zombie thread, but since I started this I thought it might be ok.

I'm running into an issue when I try to apply an XSL stylesheet (2.0) that uses a result-document with the steps that Adrian outlined in his post. The only scenario where this works is in the debugger -- I've followed his steps on single files, both in and separate from a project, but I'm not getting any output at all.

Is this a problem with the way I'm using the Output tab in the Edit Scenario dialog?
1) Document > Transformation > Configure Transformation Scenario
2) XML URL: ${currentFileURL}, XSL URL: ...browse...
3) Output tab: select 'Save As...' -- no matter what I try here, I'm not getting anything to work. Is there a conflict with the result-document in the stylesheet?

Thanks,
Bridger
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: problems with transformation scenarios

Post by adrian »

Hi,

I assume the xsl:result-document has a href attribute that points to the files. If the value of the href attribute is a relative URI, then it is resolved relative to the directory of the output file(The one you set in the Save As field from the Output tab).
If the href attribute is not specified, the content will be written in the output file as long as there's only a single result-document that has no href.

Could you please tell me what value did you use in the Save As field?

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
bds
Posts: 47
Joined: Mon Jun 26, 2006 10:40 pm

Re: problems with transformation scenarios

Post by bds »

hi Adrian,
thanks for your time. The stylesheet is a simple identity transform w/ a new file name on the output:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:result-document href="{concat(ead/eadheader/eadid, '.xml')}">
<xsl:copy-of select="."/>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
I've tried the following:
${cfd}/${cfn}
${cfd}/${cfn}-out.xml
${cfd}/
${homeDir}
~/{$cfn}-out.xml
${pd}

I'm guessing that using the ${cfn} with the result-document is incorrect, but my other attempts have failed as well. Thanks again for your assistance with this.
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: problems with transformation scenarios

Post by adrian »

What version and build number of Oxygen are you currently using(Help -> About)?


Note that only the first two items are supposed to work correctly:
${cfd}/${cfn}
${cfd}/${cfn}-out.xml

These each correctly point to a filename from the current file directory.

${cfd}/, ${homeDir} and ${pd} will not work because they each point to an existing directory. A path to a filename must be specified in the "Save As" field.

~/{$cfn}-out.xml will not work as expected. '~' represents the user home in a console command, it's a special character specific to the console. However, it will not be expanded to the home directory path when used in Oxygen. Instead you will end up with a new directory named '~' in the current directory.


Have you checked if the concat from the stylesheet yields a correct file name?
e.g.

Code: Select all

<xsl:variable name="fname">
<xsl:value-of select="concat(ead/eadheader/eadid, '.xml')"/>
</xsl:variable>
<xsl:message select="$fname"/>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply