'namespaceuri()' is an unknown XSLT function

I

IvarZap

When transforming with the automatically generated upgrade.xsl (from
Infopath), and if the source form has a rich text content, I get the above
error.

This happens when I call the template from a c# programa with a
System.Xml.Xsl.XslTransform class, but upgrading from Infopath it works
fine.

The problem is that I need to upgrade all forms in a library because when
merging old forms into a new created form, the new attributes/elements are
not added to the merged form.


Any idea?


Thanks
 
O

Oleg Tkachenko [MVP]

IvarZap said:
When transforming with the automatically generated upgrade.xsl (from
Infopath), and if the source form has a rich text content, I get the above
error.

This happens when I call the template from a c# programa with a
System.Xml.Xsl.XslTransform class, but upgrading from Infopath it works
fine.

The problem is that I need to upgrade all forms in a library because when
merging old forms into a new created form, the new attributes/elements are
not added to the merged form.

It's namespace-uri(), not namespaceuri().
 
I

IvarZap

Yes. That's the message. However, in the stylesheet there is no
namespaceuri() function but only namespace-uri().

One more data. If I transform with the msxsl.exe program it works fine.

Is this a bug of System.Xml.Xsl?
 
M

Martin Honnen

IvarZap said:
That's the message. However, in the stylesheet there is no
namespaceuri() function but only namespace-uri().

One more data. If I transform with the msxsl.exe program it works fine.

Is this a bug of System.Xml.Xsl?

Try to reduce the stylesheet to the minimum and post it or at least show
us relevant excerpts so that we can check what the stylesheet does and
for which kind of function call you get the error message.
 
I

IvarZap

It looks like it happens always with rich text content. For an example (this
is the automatically generated upgrade.xsl to a really simple Infopath form
which consists on a rich text field alone "m:richTextField" and later added
a new attribute "my:newAttribute").

upgrade.xsl:
--------------------------------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-01-04T15:33:26"
xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"
xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:eek:utput encoding="UTF-8" method="xml"/>
<xsl:template match="text() |
*[namespace-uri()='http://www.w3.org/1999/xhtml']" mode="RichText">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="/">
<xsl:copy-of select="processing-instruction() | comment()"/>
<xsl:choose>
<xsl:when test="my:myFields">
<xsl:apply-templates select="my:myFields" mode="_0"/>
</xsl:when>
<xsl:eek:therwise>
<xsl:variable name="var">
<xsl:element name="my:myFields"/>
</xsl:variable>
<xsl:apply-templates select="msxsl:node-set($var)/*" mode="_0"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>
<xsl:template match="my:myFields" mode="_0">
<xsl:copy>
<xsl:attribute name="my:newAttribute">
<xsl:value-of select="@my:newAttribute"/>
</xsl:attribute>
<xsl:element name="my:richTextField">
<xsl:apply-templates select="my:richTextField/text() |
my:richTextField/*[namespace-uri()='http://www.w3.org/1999/xhtml']"
mode="RichText"/>
</xsl:element>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
-------------------------------------------

When applied to this .xml file generated with Infopath after filling the
form (with no my:newAttribute):
form2.xml:
--------------------------
<?xml version="1.0" encoding="UTF-8"?>
<?mso-infoPathSolution solutionVersion="1.0.0.2" productVersion="11.0.6565"
PIVersion="1.0.0.0"
href="file:///C:\Documents%20and%20Settings\IvarZapata2\My%20Documents\Desktop\UpgradeInfopath\Template1.xsn"
name="urn:schemas-microsoft-com:eek:ffice:infopath:Template1:-myXSD-2006-01-04T15-33-26"
?><?mso-application progid="InfoPath.Document"?><my:myFields
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-01-04T15:33:26"
xml:lang="es">
<my:richTextField>
<div xmlns="http://www.w3.org/1999/xhtml">Rich text content</div>
<div xmlns="http://www.w3.org/1999/xhtml"></div>
</my:richTextField>
</my:myFields>
-------------------------

The program I use is really simple:

using System;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

class QuickXslTransformer
{
private XslTransform xslt = new XslTransform();

public QuickXslTransformer(
string source,
string stylesheet,
string output)
{
xslt.Load(stylesheet);
xslt.Transform(source, output, null as XmlResolver);
}


/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
QuickXslTransformer o;
o = new QuickXslTransformer(args[0], args[1], args[2]);
}
catch (Exception e)
{
Console.WriteLine(
"Unable to apply the XSLT transformation.");
Console.WriteLine("Error:\t{0}", e.Message);
Console.WriteLine("Exception: {0}", e.GetType().ToString());
Console.ReadLine();
}

return;
}
}
 
M

Martin Honnen

IvarZap said:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-01-04T15:33:26"
xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"
xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:eek:utput encoding="UTF-8" method="xml"/>
<xsl:template match="text() |
*[namespace-uri()='http://www.w3.org/1999/xhtml']" mode="RichText">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="/">
<xsl:copy-of select="processing-instruction() | comment()"/>
<xsl:choose>
<xsl:when test="my:myFields">
<xsl:apply-templates select="my:myFields" mode="_0"/>
</xsl:when>
<xsl:eek:therwise>
<xsl:variable name="var">
<xsl:element name="my:myFields"/>
</xsl:variable>
<xsl:apply-templates select="msxsl:node-set($var)/*" mode="_0"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>
<xsl:template match="my:myFields" mode="_0">
<xsl:copy>
<xsl:attribute name="my:newAttribute">
<xsl:value-of select="@my:newAttribute"/>
</xsl:attribute>
<xsl:element name="my:richTextField">
<xsl:apply-templates select="my:richTextField/text() |
my:richTextField/*[namespace-uri()='http://www.w3.org/1999/xhtml']"
mode="RichText"/>
</xsl:element>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
-------------------------------------------

When applied to this .xml file generated with Infopath after filling the
form (with no my:newAttribute):
form2.xml:
--------------------------
<?xml version="1.0" encoding="UTF-8"?>
<?mso-infoPathSolution solutionVersion="1.0.0.2" productVersion="11.0.6565"
PIVersion="1.0.0.0"
href="file:///C:\Documents%20and%20Settings\IvarZapata2\My%20Documents\Desktop\UpgradeInfopath\Template1.xsn"
name="urn:schemas-microsoft-com:eek:ffice:infopath:Template1:-myXSD-2006-01-04T15-33-26"
?><?mso-application progid="InfoPath.Document"?><my:myFields
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-01-04T15:33:26"
xml:lang="es">
<my:richTextField>
<div xmlns="http://www.w3.org/1999/xhtml">Rich text content</div>
<div xmlns="http://www.w3.org/1999/xhtml"></div>
</my:richTextField>
</my:myFields>

Indeed when I use XslTransform with .NET 1.1 then at runtime during
executing the Transform method it generates the error
"Unhandled Exception: System.Xml.Xsl.XsltException: 'namespaceuri()' is
an unknown XSLT function."

When I compile and run with .NET 2.0 (still using XslTransform) no error
occurs so this seems like you are running into a bug in .NET 1.1 which
got fixed for 2.0.

When I compile and run with .NET 2.0 using the new XslCompiledTransform
there is also no problem.

MSXML 3 and 4 also work without problems.

As far as I can see those XPath expressions and XSLT patterns in that
stylesheet are syntatically correct.


If you change e.g.
*[namespace-uri()='http://www.w3.org/1999/xhtml']
to e.g.
xhtml:*
with the xhtml prefix bound to the namespace URI
http://www.w3.org/1999/xhtml the problem will hopefully vanish but I am
not sure that is an option for you as you said those stylesheets are
automatically generated.
 
O

Oleg Tkachenko [MVP]

IvarZap said:
<xsl:template match="text() |
*[namespace-uri()='http://www.w3.org/1999/xhtml']" mode="RichText">

That looks like a bug in XslTransform. It doesn't like namespace-uri()
in match attribute somehow. In fact you can use instead

<xsl:template match="text() | xhtml:*" mode="RichText">

but you said it's generated stylesheet so that's not a solution.
Then consider moving to .NET 2.0. XslCompiledTransform in .NET 2.0 is
much better XSLT engine.
Alternatively you can modify stylesheet after it's generated or before
executing it to workaround this particular bug. E.g. load it into
XmlDocument and make above modification.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top