title: XML-22003: (Error) Unable to write to output stream
body: <p>I am getting XSL Exception "XML-22003: (Error) Unable to write to output stream" while trying to generate XMLs from a XMLStylesheet using Java. The location of the output XML is dynamically defined in the Stylesheet using a parameter set during runtime.
  Also, the XML is generated in the location of the stylesheet but I want to get it generated at the specified location only.
  I have tried a lot but it seems I am the only person who has got this error.</p>
  
  <p>Below is the snapshot of the <strong>Java code</strong> for setting the location parameter and to process the stylesheet:</p>
  
  <pre><code>XSLProcessor processor = new XSLProcessor();
  XSLStylesheet xsl =null;
  
  //xslURL is the URL of the Stylesheet stored.
  xsl = processor.newXSLStylesheet(xslURL);
  Transformer xsltTransformer = xsl.newTransformer();
  String filenamePath = finalXMLLocation + "PMTFolder/FinalXMLs/";
  
  xsltTransformer.setParameter("filenamePath","'"+ filenamePath + "'");
  xsltTransformer.setParameter("itemCodes", "'" + itemCodes + "'");
  
  //DiagramXML is the location of the XML which has to be transformed.
  InputStream inputStream = new FileInputStream(diagramXML);
  StreamSource in = new StreamSource(inputStream);
  
  final StringWriter stringWriter=new StringWriter();
  PrintWriter printWriter = new PrintWriter(stringWriter);
  StreamResult outputTarget=new StreamResult(printWriter);
  xsltTransformer.transform(in, outputTarget);
  </code></pre>
  
  <p>Below is the snapshot of the XMLStylesheet:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet version="2.0"   xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions" xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:ehdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.esb.server.headers.ESBHeaderFunctions" xmlns:orcl="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc" xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath" xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"  xmlns:ns7="http://xmlns.oracle.com/EnterpriseObjects/Core/CommonEBO/V1" xmlns:ns8="http://xmlns.oracle.com/EnterpriseObjects/Core/Common/V2"  xmlns:ns1="http://xmlns.oracle.com/EnterpriseObjects/Core/EBO/ItemComposition/V1"  xmlns:prodtool="URI:prodtool" exclude-result-prefixes="xsl xref xp20 bpws ora ehdr orcl ids hwf"&gt;
      &lt;xsl:output omit-xml-declaration="yes" method="xml" indent="yes" name="xml"/&gt;
      &lt;xsl:param name="filenamePath" value ="c:/code_ws/PMTData/FinalXML"/&gt;
  
      &lt;xsl:param name="itemCodes"/&gt;
      &lt;xsl:key name="attrModelPath" match="/prodtool:Diagram/pov/attr/atCalcProdAt/AtCalcModPat" use="concat(@productOfferingIdentifier,',',@productOfferingName,',',@productOfferingRelationshipDirection,',',@productOfferingRelationshipType,',',@isRootSalesRelationContext,',',@childProductOfferingIdentifier,',',@childProductOfferingName,',',@productAttributeName,',',@productAttributeDataType)"/&gt;
      &lt;xsl:template match="/"&gt;
          &lt;xsl:for-each select="/prodtool:Diagram/pov"&gt;
              &lt;xsl:if test="not(contains($itemCodes,@primaryIdentifier))"&gt;
                  &lt;xsl:variable name="filePath" select="concat($filenamePath,concat(concat(concat('ProductOffering_',@primaryIdentifier),'_'),concat(@version,'.xml')))"/&gt;
                  &lt;xsl:result-document href="{$filePath}" format="xml"&gt;
  </code></pre>
  
  <p>Below is the error I am getting:</p>
  
  <pre><code>XSL Exception occured: file:/C:/PMTData/featureSpecification_dpc.xsl&lt;Line 39, Column 57&gt;: XML-22003: (Error) Unable to write to output stream (C:/PMTData/FinalXMLs/FeatureSpecification/FeatureSpecification_C0401116_A.101.xml).
  </code></pre>