Imran Gani
Imran Gani

Reputation: 1

xsl:result-document throws "The system identifier of the principal output file is unknown" error

I am trying to split output into multiple file by using xsl:result-document. But I am getting error as "The system identifier of the principal output file is unknown".

Input XML:

<ArrayOfBatch>
 <Batch>
  <BatchName>BatchName-1</BatchName>
 </Batch>
 <Batch>
  <BatchName>BatchName-2</BatchName>
 </Batch>
 <Batch>
  <BatchName>BatchName-3</BatchName>
 </Batch>
</ArrayOfBatch>

XSLT Format:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" version="3.0" exclude-result-prefixes="fn xs">
 <xsl:output method="xml" indent="yes"/>
 <xsl:template match="/">
  <xsl:for-each select="/ArrayOfBatch/Batch">
   <xsl:result-document href="Batch-{position()}.xml" method="xml" omit-xml-declaration="yes">
    <xsl:copy-of select="*"/>
   </xsl:result-document>
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

We are using .Net to run xslt with below transformation

public static string SaxonProcessorXSLT(string xmlToExport, string xslStylesheet)
{
  using (StringReader xmlStream = new StringReader(xmlToExport))
  {
    using (StringReader xslStream = new StringReader(xslStylesheet))
    {
      Processor xsltProcessor = new Processor();
      DocumentBuilder documentBuilder = xsltProcessor.NewDocumentBuilder();
      documentBuilder.BaseUri = new Uri("file://");
      XdmNode xdmNode = documentBuilder.Build(xmlStream);

      XsltCompiler xsltCompiler = xsltProcessor.NewXsltCompiler();
      XsltExecutable xsltExecutable = xsltCompiler.Compile(xslStream);
      XsltTransformer xsltTransformer = xsltExecutable.Load();
      xsltTransformer.InitialContextNode = xdmNode;

      using (StringWriter stringWriter = new StringWriter())
      {
        Serializer serializer = xsltProcessor.NewSerializer();
        serializer.SetOutputWriter(stringWriter);
        xsltTransformer.Run(serializer);
        return stringWriter.ToString();
      }
    }
  }
}

I have done some R&D on this and found the similar issue here but its not solving my problem. I have tried by using SAXON-HE and SAXON-EE (dll) on version 2.0 and 3.0. Looking for quick response. Thanks in advance.

Upvotes: 0

Views: 423

Answers (1)

Michael Kay
Michael Kay

Reputation: 163595

You have given a relative URI in the @href attribute of xsl:result-document. This is treated as being relative to the "principal output URI" of the transformation. The error message is telling you that the principal output URI has not been supplied. This is because you invoked the transformation without supplying it.

You haven't told us how you invoked the transformation. The details will depend on whether you used the command line, the JAXP transformation API, the s9api transformation API, or perhaps the fn:transform() function. Each of these APIs gives you an opportunity to supply the required URI.

Perhaps the most common reason for the problem (but now I'm guessing) is that you used the JAXP transformation API, and specified as the destination for the transformation a StreamResult containing a Stream or Writer but no systemId.

(I'm a little surprised that you should link to another question in which I gave exactly the same information, and stressed that to answer it in detail, we need to see how you invoked the transformation. Many people would close this as a duplicate...)

Upvotes: 0

Related Questions