Register  Login       Search  
Forum  
 
  
 
Forum  Forum     
 
SearchForum Home
  XML Lab Products  nxslt  -mo w/o -o reso...
 -mo w/o -o resolves paths from /
 
earlNameless
3 posts
Joined
1/16/2007

-mo w/o -o resolves paths from /
Posted: 16 Jan 07 1:28 PM (United States)
When I run the nxslt2 with -mo option, but without specifying an output file with the -o option, the paths for multiple document output are resolved from the root of the drive.

Example:
xslt transformation outputs to HelloWorld.txt. I run the nxslt2 in C:\temp\ folder as: nxslt2 world.xml hello.xslt -mo
This results in C:\HelloWorld.txt being created instead of C:\temp\HelloWorld.txt.

Fix:
In NxsltMain.cs on line 182:
Change: results.XmlResolver = new OutputResolver(Path.GetDirectoryName(options.OutFile));
To: results.XmlResolver = new OutputResolver(Directory.GetCurrentDirectory());

Why:
There is a check for Output file, the location where that happens already has a check for OutFile being null, there is no reason to use the null when passing to OutputResolver.

Other:
There is some problem in that when specifying the -o option, the problem still persists, and I am not sure exactly why. In constructor of OutputResolver the this.baseUri ends up being file://c:/, which is incorrect.
Zef
5 posts
Joined
1/18/2007

Re: -mo w/o -o resolves paths from /
Posted: 18 Jan 07 3:20 AM (Netherlands)

I also noticed this issue. Furthermore, the output path is html-encoded, so e.g. spaces in de path are replaced by "%20".

Fortunately these bugs are easy to fix:

1. File IXmlTransform.cs, line 126:

this.baseUri = new Uri(new Uri(Directory.GetCurrentDirectory() + "/"), baseUri + "/");

Insert the following line just before the original line above:

if (string.IsNullOrEmpty(baseUri)) baseUri = ".";

If the given baseUri parameter is empty, then the Uri will be created with relativeUri equal to "./" (current directory) instead of "/" (root directory).This solves the issue of the output being saved relative to the root directory.

2. File OutputState.cs, line 67:

string outFile = outResolver.ResolveUri(null, href).AbsolutePath;

Replace "AbsolutePath" (encoded server path) with "LocalPath" (local file system path). This prevents the output path from being encoded.

Greetingz,

Zef

olegt
85 posts
www.xmllab.net
Joined
2/25/2005

Re: -mo w/o -o resolves paths from /
Posted: 18 Jan 07 3:40 AM (Israel)
Thanks guys! I'll fix it.
Oleg Tkachenko, Microsoft MVP for XML, MCPD
http://www.XmlLab.Net | http://blog.tkachenko.com
Zef
5 posts
Joined
1/18/2007

Re: -mo w/o -o resolves paths from /
Posted: 18 Jan 07 5:55 AM (Netherlands) Modified By Zef  on 1/18/2007 6:00:30 AM)
Thanx Oleg!

I just noticed another small issue concerning the nxsl2 MSBuild task and the multiple output option:

For a certain transformation, I need the output filename to be generated from the value of certain element in the source xml file. I use nxsl2  to apply this transformation, as it supports the exsl:document extension.

Basically I select the root element within an exsl:document container element, and then apply child templates.

<xsl:template match="/">
   <exsl:document href="{$SaveFilePath}" method="xml" version="1.0" indent="yes">
      <xsl:copy>
         <xsl:apply-templates select="@* | node()"/>
      </xsl:copy>
   </exsl:document>
</xsl:template>

Until now I applied this transformation using the stand alone nxslt2.exe utility, with the -mo option flag, works great.

Today I updated the MSBuild project to make use of the XmlLab.NxsltTasks.MSBuild.dll custom task instead. Now I notice that the transform not only generates a custom output (via
the exsl:document declaration), but also an empty output file having the same filename as the input file.

Off course no big problem, I simply added an MSBuild task to delete the empty file afterwards. But it would be better if the behaviour of the MSBuild task was the same as that of the stand-alone nxsl2.exe.

Greetings,

Michel
earlNameless
3 posts
Joined
1/16/2007

Re: -mo w/o -o resolves paths from /
Posted: 19 Jan 07 11:31 AM (United States)
Thanks. Awaiting the next version...
  XML Lab Products  nxslt  -mo w/o -o reso...
Forum Home  Search