Wednesday, October 10

Xslt compilation error when testing map with inline XSLT

I recently came across this non-descript error while testing a map which had an inline XSLT call template on some nodes.

XSLT compile error at (116,6). See InnerException for details. Prefix 'ns1' is not defined

It was due to a silly oversight really, but it could throw you at first because of it's vagueness.

In my inline XSLT call template, I had a test script which then created various nodes based on certain conditions being met...

<xsl:if test="/*[local-name()='MyTopNode' and namespace-uri()='http://www.namespace.com/namespace/']/*[local-name()='NextNode' and namespace-uri()='http://www.namespace.com/othernamespace/']/*[local-name()='Warnings' and namespace-uri()='http://www.namespace.com/namespace/']">
    <xsl:element name="ns1:Warnings">  
   <xsl:for-each select="./*[local-name()='Warning' and namespace-uri()='http://www.namespace.com/anynamespace/']">
  <xsl:element name="ns1:Warning">


Note the bit in red. I have obviously failed to define what the prefix stands for, which means that if it so happens that BizTalk changes the prefix whilst mapping, ns1 suddenly means nothing and voila, the error is thrown.

To fix this, I simply modified the template as shown below to define exactly what I want my prefix(es) to represent and the error disappeared

<xsl:if test="/*[local-name()='MyTopNode' and namespace-uri()='http://www.namespace.com/namespace/']/*[local-name()='NextNode' and namespace-uri()='http://www.namespace.com/othernamespace/']/*[local-name()='Warnings' and namespace-uri()='http://www.namespace.com/namespace/']">
<xsl:element name="
ns1:Warnings" xmlns:ns1="http://www.namespace.com/whatIwantItToBe"/>
<xsl:for-each select="./*[local-name()='Warning' and namespace-uri()='http://www.namespace.com/anynamespace/']">
<xsl:element name="ns1:Warning">

No comments:

Post a Comment