This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problems with resolving URIs in under Java JDK 1.4 Beta 3



I have written a set of templates, that work when invoked directly using
an xslt processor (I used both Saxon and MSXML 3.0 SP1 while I was
creating the templates).

The templates output their results directly to output files (using
xsl:document) and tend to have the following form:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
<xsl:output omit-xml-declaration="yes" method="text"/>

<xsl:param name="xmlDirName"
select="'file:///C:/Projects/linx/xTrade/src/com/linx/xtrade/messaging/g
enerator/xmlmessagedefinition/_testData'"/>
<xsl:param name="outputDirName"
select="'C:/Projects/linx/xTrade/src/com/linx/xtrade/messaging/generator
/xmlmessagedefinition/_testData/tmp'"/>
<xsl:param name="fileDelimiter" select="&#39;/&#39;" />

<xsl:variable name="fixTagXmlFile" select="concat($xmlDirName,
'/fixtagsdef.xml')"/>
<xsl:variable name="simpleDataTypeXmlFile" select="concat($xmlDirName,
'/valuesdef.xml')"/>
<xsl:variable name="complextDataTypeXmlFile" select="concat($xmlDirName,
'/fixfieldgroupsdef.xml')"/>

<xsl:variable name="messageListXmlFile" select="concat($xmlDirName,
'/fixmessagedef.xml')"/>
<xsl:variable name="messageDefinitionXmlDir" select="concat($xmlDirName,
'/fixmessages')"/>

<xsl:variable name="allFixTagNodes" select="document ($fixTagXmlFile)"/>
<xsl:variable name="allsimpleDataTypeNodes" select="document
($simpleDataTypeXmlFile)"/>
<xsl:variable name="allComplexDataTypeNodes" select="document
($complextDataTypeXmlFile)"/>


	<xsl:template match="/">
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template match="blah1">
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template match="blah2">


<xsl:variable name="currentComponentBlockNode" select="."/>
<xsl:variable name="currentComponentBlockName"
select="string($currentComponentBlockNode/@name)"/>
<xsl:variable name="regularFieldNodes"
select="$allFixTagNodes/fixtagsdef/fixtag[@id =
$currentComponentBlockNode/fixfields/fixfield/@ref]"/>
<xsl:variable name="allComplexFieldNodes"
select="$currentComponentBlockNode/fixfields/fixfieldgroup"/>
<xsl:variable name="componentBlockFieldNodes"
select="$allComplexFieldNodes[not(contains(@ref, 'Group'))]"/>
<xsl:variable name="repeatingGroupFieldNodes"
select="$allComplexFieldNodes[contains(@ref, 'Group')]"/>

<xsl:variable name="currentFileName" select="concat ($outputDirName,
concat($fileDelimiter, concat($currentComponentBlockName,
&#39;.java&#39;)))" />
<xsl:document href="{$currentFileName}">

.
.
.
. Do some more xslt work
.
.
.
.

</xsl:document>
</xsl:if>

		<xsl:apply-templates/>
	</xsl:template>

	<xsl:include href="toConstantName.xsl" />
	<xsl:include href="toObjectName.xsl" />
	<xsl:include href="mapFixFieldTypeToInternalType.xsl" />
	<xsl:include href="mapFixFieldTypeToEnumType.xsl" />
	<xsl:include href="getFieldNameFromTagNum.xsl" />

</xsl:stylesheet>

To automate the transformation process, I decided to use the TraX api in
Java JDK 1.4 Beta 3. I notices that I was to successfully excute the
templates if I removed the includes and replaced them with the in-line
code.

With the includes I was initially getting the following Error:

javax.xml.transform.TransformerConfigurationException:
javax.xml.transform.TransformerException:
javax.xml.transform.TransformerException: Had IO Exception with
stylesheet file: toConstantName.xsl

I didn't think that I needed to provide a custom URIResolver as all the
paths are relative, so I tried setting a systemID for the source items.
When I do this, I get the following error, which makes no sense to me:

javax.xml.transform.TransformerException:
javax.xml.transform.TransformerException:
org.apache.xml.utils.URI$MalformedURIException: The scheme is not
conformant.

The java code looks like this:

Where 

- xmlFileName = "c:/test/file.xml"
- xslFileName = "c:/test/firstStage.xsl"
- outputDir = "c:/tmp"

---

	void generate (String xmlFileName, String xslFileName, String
outputDir)
	{


	  try
	  {
		String xmlSystemId = new
File("c:/test").toURL().toExternalForm( );
		String xsltSystemId = new
File("c:/xsl").toURL().toExternalForm( );


		// create the transformerfactory & transformer instance
		TransformerFactory tf =
SAXTransformerFactory.newInstance();

		// process the XSLT stylesheets into a Templates
instance
		// with our TransformerFactory instance

		Source xslSource = new StreamSource(new
FileInputStream(xslFileName));
		xslSource.setSystemId(xsltSystemId);
		Templates mappingTemplate = tf.newTemplates(xslSource);

		Transformer mappingTransFormer    =
mappingTemplate.newTransformer();;
		Result transJavaGenerationResult       = null;
		Source xmlSource                      = null;
		StreamSource xmlJavaGenerationSource  = null;

		ByteArrayOutputStream xmlByteArrayOutputStream = new
ByteArrayOutputStream();

		xmlSource = new StreamSource(new
FileInputStream(xmlFileName));
//		xmlSource.setSystemId(xmlSystemId);
		// create the result target of the transformation can be
a DOM node, SAX stream,
		// or a java out stream/reader

		// We dump the output of the aggregation transformation
into a ByteArrayOutputStream
		transJavaGenerationResult = new
StreamResult(xmlByteArrayOutputStream);

		// now we set the input parameters for the style sheets
		mappingTransFormer.setParameter("xmlDirName", "\'" +
xmlSystemId + "\'");
//		mappingTransFormer.setParameter("outputDirName", "\'" +
outputDir + "\'");
		mappingTransFormer.setParameter("outputDirName", "\'" +
new File(outputDir).toURL().toExternalForm( ) + "\'");
//		mappingTransFormer.setParameter("fileDelimiter", "\'" +
FileAccess.FILE_PATH_ELEMENT_SEPARATOR + "\'");
		mappingTransFormer.setParameter("fileDelimiter",
"\'\'");

		// execute transformation & fill result target object.
The the java files are written
		// directly to the file system, by the xslt processor
		mappingTransFormer.transform(xmlSource,
transJavaGenerationResult);

		System.out.println("+++ Generated the java file for: " +
xmlFileName  + "+++++" );
	
System.out.println("====================================================
==============\n\n " );

		// Clear out tmp stuff
		mappingTemplate = null;
		transJavaGenerationResult = null;
		xmlSource = null;
		xmlByteArrayOutputStream.reset();
	  }
	  catch (Exception ex)
	  {
		System.out.println("\n\n\n !!!!!!!! generateMessages
failed because of: " + ex + " !!!!!!!!\n\n\n ");
		System.exit(-20);
	  }
	}
----

Any help would be greatly apreaciated...

rgds.as
___________________________________________________________________ 
Ahmed Sako                                  asako@golinx.com
Linx, New York                               
(212) 905-3079
___________________________________________________________________
"The beauty remains; the pain passes" - Pierre-Auguste Renoir 
 




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]