nxslt.exe Command Line Utility

| 26 Comments | 1 TrackBack

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

Related Blog Posts

1 TrackBack

TrackBack URL: http://www.tkachenko.com/cgi-bin/mt-tb.cgi/174

TITLE: Israeli .Net Bloggers URL: http://weblogs.asp.net/rosherove/archive/0001/01/01/75893.aspx IP: 66.129.67.202 BLOG NAME: ISerializable DATE: 02/24/2004 09:44:00 AM Read More

26 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.

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 ;)

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)/*"/>

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?

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.

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 ?

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)/*"/>

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

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.

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

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.

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>

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

hi oleg,

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

Nice work, very handy. Thanks!

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.

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

thanks. cool stuff.

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

Thank you,

BR,
~A


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>

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>

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

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

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

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

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.

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.

Leave a comment