February 21, 2004

nxslt.exe Command Line Utility

Dummy entry to provide single place for nxslt.exe utility comments.

February 21, 2004 1:09 AM | #XML in .NET
Comments

Thanks for you comments, Drazen!

I've fixed namespace declaration bug you mention, thanks!
In fact, nxslt can be built pretty well in Visual Studio 2003, I just call makefile in a post-build event.
Debug mode is interesting, but I'm not sure what for. Anyway, you can debug nxslt in Visual Studio 2003 by commenting out post-build event script.
And unfortunately I can't get rid of post-build event script, it's necessary to rename EXLST functions (exsl:nodeset -> exsl:node-set) and this can't be done in pure .NET.

New nxslt home is at http://www.xmllab.net. There you can download new 1.6 version.

Posted by: Oleg Tkachenko at June 30, 2005 2:48 PM

Before I start listing bugs/problems, let me thank you for the work you've done. Very nice utility with a complete yet not overloaded feature set.
There are some issues, though. The command line parameter parsing is unreliable. I think you might have overloaded the meaning of some switches and a minor cleanup would improve things. In the following example:
nxslt.exe SourceAndEmbeddedXSLT.xml -mo -pi -ext fs:MyNS.MyClass xmlns:fs='urn:myns' -af MyNS.dll
nxslt responds with "Prefix 'fs' cannot be resolved. Use xmlns:fs='...' to bind 'fs' to a URI.".
I debugged and found that because the namespace binding is not a separate switch (why not something like -ns xmlns:xx='...'?) it is not detected properly unless the stylesheet is listed before it on the command line. My example has stylesheet embedded in the XML file (which works great btw) so it is not present at all on the command line.
I appreciate that you give out the source code, but could you please:
1. Build using Visual Studio as well as using the provided makefiles
2. Turn on debug info in debug configuration
3. Get rid of post build step where you disassemble the code, rename methods, and assemble back; with this active, one cannot debug at all
I was able to work around all of the above issues, but it was a bit of pain in the ass ;)

Posted by: Drazen Dotlic at June 24, 2005 9:09 AM

Sure you can. Technically speaking XSLT accepts multiple inputs and all input documents are equivalent, it's just one of them - source - is implicit.
Just beware that document() function returns document root, so the following is infinite loop:
<xsl:template match="/">
<xsl:apply-templates select="document($foo)"/>
<xsl:template>

It's good practice always to apply templates to root element then:
<xsl:apply-templates select="document($foo)/*"/>

Posted by: Oleg Tkachenko at May 29, 2005 11:55 AM

Thanks again Oleg. Last question - can I apply my stylesheet (XSLT) to the document included using the document() function, and will it handle any recurrsion?

Posted by: David at May 29, 2005 7:47 AM

David, sure it can. It's perectly valid to build URL dynamically and pass it to document() function. The only limitation - document() funcion can only load XML documents, not plain text.

Posted by: Oleg Tkachenko at May 27, 2005 10:02 PM

Thanks Oleg.

Will try this.

I should have pointed out, the full URL of the object I need to retrieve is not part of the XML input stream - I am creating the URL from an attribute.......can the document function use xsl:variables ?

Posted by: David at May 27, 2005 8:04 PM

nxslt tool applies XInclude during parsing of source XML and XSLT stylesheet documents, not during output phase.

Basically to dynamically include XML document in XSLT you don't need XInclude. Just use document() function:

<xsl:copy-of select="document(@your_attribute)"/>

Or even

<xsl:apply-templates select="document(@your_attribute)/*"/>

Posted by: Oleg Tkachenko at May 25, 2005 6:25 PM

Hi,

What order does processing occur in -> XML->XSLT->OUTPUT->XINCLUDES or XML->XSLT->XINCLUDE->OUTPUT ?

I'm trying to dynamically create the XINCLUDE from an attribute on a node
in the XML input stream, if I drop the -xi switch, NXSLT throws an error, but with the -xi switch I get output, but it's not correct, looking like the variable substitution I have in my xinclude has been bypassed.

Can Xincludes be dynamically generated from content and then resolved?

The objective is to retrieve an XML document denoted by the attribute in the XML stream and incorporate into the output.

Thanks - David

Posted by: David at May 25, 2005 4:53 PM

Michael, here is a sample:

nxslt.exe source.xml style.xsl -ext user:My.Extensions xmlns:user="http://www.user.com" -af d:\temp\extensions.dll

This binds My.Extensions class from d:\temp\extensions.dll to user namespace prefix. In XSLT you have to declare user namespace and then you can call My.Extensions class methods using user:Function() syntax.

Posted by: Oleg Tkachenko at April 20, 2005 1:31 PM

How do I bind a class in a C# class library DLL to an extension object namespace?

Posted by: Michael S. Scherotter at April 19, 2005 9:46 PM

Orlando, .NET XSLT Processor - XslTransform class doesn't support that.
nxslt doesn't support such feature either. Btw, it's good idea to add such a feature, thanks.
But take a look at http://www.tkachenko.com/blog/archives/000266.html for a sample how to implement this stuff.

Posted by: Oleg Tkachenko at April 12, 2005 5:53 PM

Hi,
I'm trying to change the encoding of the html so that a utf-8 page going through nxslt will produce an html page where the decimal equivalent will be shown in the html for special special Character (i.e. Latin symbols or ©).

This what I have in my xsl, what am I doing wrong?

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="us-ascii" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

Posted by: Orlando at April 12, 2005 5:16 PM

Hey, that's good idea, Devo! I'll check it out.

Posted by: Oleg Tkachenko at April 12, 2005 12:06 PM

hi oleg,

Are in your plans, create a nant contrib task with this nice tool ?
Devo

Posted by: Devo at April 11, 2005 6:20 PM

Nice work, very handy. Thanks!

Posted by: Jason Mauer at April 9, 2005 11:15 PM

Tim, this is called an intra-document reference in XInclude.
Unfortunately XInclude.NET doesn't support it yet. I'm planning to implement it soon.

Posted by: Oleg Tkachenko at February 21, 2005 10:50 PM

Never heard. Go ahead if you think it's gonna be useful.

Posted by: Oleg Tkachenko at February 13, 2005 1:00 PM

thanks. cool stuff.

i might want to port this to java 1.5. do you know if someone tried it ?

Thank you,

BR,
~A

Posted by: anjan bacchu at February 5, 2005 8:16 PM


nxslt rocks and so does XInclude.NET! Thank you so much Oleg.


I'm using nxslt with XInclude to include parts of a document in itself. I have to do a pre-processing step to strip out the XInclude nodes to avoid circular references. In case anyone else needs it, here's the simple XSLT that I'm using to accomplish that. If anyone knows a better way to do this let me know. Does the XInclude spec define a way of doing this?


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method = "xml" version = "4.0" encoding="ASCII" indent = "yes" />

<!-- Identity template -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<!-- This template strips out elements with the XInclude namespace. You would use this as a pre-processing step if you're going to xinclude parts of a document in itself, to avoid circular references. -->
<xsl:template match="*[namespace-uri()='http://www.w3.org/2003/XInclude']" />

</xsl:stylesheet>

Posted by: Tim at December 22, 2004 7:52 PM

mike, nxslt.exe is basically XSLT utility and it does require stylesheet.
I'll consider adding such mode for nxslt.exe though.

In the meantime you can provide dummy stylesheet, which does nothing :

<xsl:stylesheet version="1.0"
xmlns:xsl="">">http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:copy-of select="/"/>
</xsl:template>
</xsl:stylesheet>

Posted by: Oleg Tkachenko at November 30, 2004 12:17 AM

I was trying to use nxslt.exe to resolve some xinclude statments in a xml file to create a new xml file without the xincludes.
I'd did this from the command line
>nxslt.exe temp.xml -o out.xml

It bombed because it didn't provide an stylesheet filename, but temp.xml uses no stylesheet.

I just want out.xml to have all the replacements of xi:include for the acutal xml files in the includes.

How can I do this?

thanks,

mike

Posted by: mike at November 29, 2004 7:55 PM

hi oleg,

wanted to send you an error report with a 20kb attachment. but both mail addrs (oleg@tkachenko.com + olegt@multiconn.com) bounced: No Storage Space

pls let me know when/where to I can resend ...

TIA, andreas

Posted by: andreas at June 2, 2004 12:05 PM

Er ... never mind. :-)

I wish I'd tried it before I posted, but this format:

works fine for me. I think my previous example was a bad format I was using due to my newbie status with XSLT.

Thanks!
Rob

Posted by: Rob Scott at May 3, 2004 10:55 PM

I'm really frustrated with myself for not being able to figure this out, but I'll be derned if I can get a simple format-date call working.

Here's the error I get when I run nxslt.exe from the command line:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Xml.Xsl.XsltException: The named template 'http://exslt.org/dates-and-times:format-date' does not exist.
at System.Xml.Xsl.CallTemplateAction.Execute(Processor processor, ActionFrame
frame)
at System.Xml.Xsl.ActionFrame.Execute(Processor processor)
at System.Xml.Xsl.Processor.Execute()
...

Here's a snippet of my transformation sheet:

...
http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
xmlns:date="">">http://exslt.org/dates-and-times">
...



In case you have a chance to look at it, I've uploaded the complete files here: http://scottclan.cc/misc/using_nxslt.zip

Thanks,
Rob

Posted by: Rob Scott at May 3, 2004 10:27 PM

Well, nxslt.exe itself isn't XSLT processor, it's just a handy wrapper around standard .NET System.Xml.Xsl.XslTransform class.
That might be some bug or might be not.
Send me a sample of your XML and XSLT, I'll take a look at the issue.

Posted by: Oleg Tkachenko at April 1, 2004 12:45 PM

I've just tried using this utility to convert WordML to HTML using the stylesheet you provided.

Thank you very much for this.

However, I've noticed a problem in transforming another stylesheet I was using previously.

I setup a variable I want to use for making comparisons to:

<xsl:variable name="Contact" select="/PPMDoc/Template/Query/QueryCriteria/ClinicianOrNurse"/>

and later get a count of records matching this variable:

<xsl:value-of select="count(Patients/Patient/OutPatients/OutPatient[1][eo_DiscussedWith=$Contact])"/>

Previously, using MSXML v4, I'd get the correct count of records matching (say count=30), but using your utility to perform the transformation, I always get 0 matches. Do you know why this might be?

Thanks again.

Posted by: Colin at March 31, 2004 2:52 PM
Post a comment




Remember Me?

Trackback Pings

Listed below are links to weblogs that reference this post:

Israeli .Net Bloggers from ISerializable
Tracked on February 24, 2004 9:44 AM