Transformation path issue

Posted on 2003-10-24
Last Modified: 2008-02-01
Hello Experts,

I am trying to Merge the xml Document in different folder in the fileSystem. I am using Java, DOM, and
XSLT to combine the xml and using xslt for transformation. I have everything working fine.

Now, My question
is that, I wanted to keep the xslt(index_sort.xsl) in a folder called "c:\Project\xslt\index_sort.xsl" and the
source xml should be in a folder called "c:\source", when I run the transformation using the index_sort.xsl
I am getting the following error

file:/C:/Project/xsl/index_sort.xsl; Line #8; Column #59; Can not load requested doc: c:\C:\Project\Source\whidata0.xml (The filename, directory name, or volume label syntax is incorrect)

If I kept everything under the folder (c:\Project) its working fine. Can somebody please help me to fix
this problem.

Here is the Java code, xslt and source xml (main and data file) as follows

public class IndexMergeSort {
    private int counter = 0;

    public void mergeIdxXML(String[] arrString, File newFile){

                  DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                  DocumentBuilder        docBuilder        = docBuilderFactory.newDocumentBuilder();
                  Document mergedDocument = docBuilder.newDocument();
                  Node     indexElement   = mergedDocument.createElement("index");
                  for (int i=0; i<arrString.length; i++) {
                        File     f                 = new File(arrString[i]);
                        Document nextDoc           = docBuilder.parse(f);
                        NodeList chunkInfoElements = nextDoc.getElementsByTagName("chunkinfo");
                        for (int j=0; j<chunkInfoElements.getLength(); j++) {
                              Node   chunkInfoNode    = chunkInfoElements.item(j);
                              Node   newChunkInfoNode = mergedDocument.importNode(chunkInfoNode, true);
                              String dataFileName     = ((Element) newChunkInfoNode).getAttribute("url");
                              String s                = f.getParent();      
                              String copyFileFrom     = s + "\\" + dataFileName;
                              ((Element) newChunkInfoNode).setAttribute("url", copyFileFrom);

                  synchronized (this) {
                        String systemID = new File("index_sort.xsl").toURL().toExternalForm(  );
                        // construct the source
                        DOMSource          xmlSource = new DOMSource( mergedDocument );
                        StreamSource       xslSource = new StreamSource( systemID );                  
                        // get the factory
                        TransformerFactory tf        = TransformerFactory.newInstance();
                         // get a transformer for this particular stylesheet
                        Transformer        t         = tf.newTransformer(xslSource);
                        // do the transformation
                        t.transform(xmlSource, new StreamResult(new File(newFile.getPath(), "Index_Merged_Data.xml")) );
            }catch(TransformerException te){
            }catch(ParserConfigurationException pce){
            }catch(SAXParseException spe){
            }catch(SAXException se){
            }catch(IOException ie){
            }catch(Exception e){


Here is the xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
   <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
   <xsl:variable name="vDataMerged" select="document(/index/chunkinfo/@url)/indexdata/key"/>
   <xsl:template match="index">
               <xsl:apply-templates select="$vDataMerged">
                   <xsl:sort select="@name" order="ascending" data-type="text"/>
   <xsl:template match="/ | node()">
           <xsl:apply-templates select="@*"/>
   <xsl:template match="text() | @*">

Main xml is pointing to the Data file is like below

Main xml
<?xml version='1.0' encoding='ISO-8859-1' ?>
<chunkinfo url="whidata0.xml" first="1-800-829-3676" last="10-day" num="102" />


Data File

<?xml version='1.0' encoding='ISO-8859-1' ?>
<key name="1-800-829-3676" >
  <key name="calling" >
    <topic name="Chapter 201.1 " url="Manuals/YGKLE/201_1.html" />
<key name="10" >
  <topic name="Chapter 1.1 ISA Plus" url="Manuals/AOAMI/1_1.html" />
  <key name="charge" >
    <topic name="Chapter 1.2 " url="Manuals/AOAMI/1_2.html" />
<key name="10-day" >
  <topic name="Chapter 1.5 Policy Changes" url="Manuals/AOAMI/1_5.html" />
  <topic name="Chapter 1.6 Policy Changes" url="Manuals/AOAMI/1_6.html" />
Question by:alagappanK
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 26

Expert Comment

ID: 9616385
You need to show us the code that isn't working. That is, the main.xml that has

<?xml version='1.0' encoding='ISO-8859-1' ?>
<chunkinfo url="whidata0.xml" first="1-800-829-3676" last="10-day" num="102" />


where the url is the one you're having problems with.

Now, the xslt document() function can take two arguments. (see:  The first is the URI of the XML, but the second can be a nodeset that indicates the baseURI.  so if you had:

<chunkinfo url="whidata0.xml" base="c:\Project\xslt\" first="1-800-829-3676" last="10-day" num="102" />

then this might work:

<xsl:variable name="vDataMerged" select="document(/index/chunkinfo/@url, /index/chunkinfo/@base)/indexdata/key"/>

Mike Sharp

Author Comment

ID: 9616630
Hello Mike,

Here is the main xml looks like when I construct the "xmlSource".

<?xml version='1.0' encoding='ISO-8859-1' ?>
<chunkinfo url="C:\Source\GroupOne\whxdata\whidata0.xml" first="1-800-829-3676" last="10-day" num="102" />

</chunkinfo><chunkinfo first="Monthly" last="YRT" num="1508" url="C:\Source\GroupTwo\whxdata\whidata0.xml">

I do not have this  base="c:\Project\xslt\". in the main xml.  I wanted to keep the xslt inside the project and the source data might be in some where in the filesystem (or SanDisk).

Can you explain what should I do now. Do you want me to include a attribute (base="c:\Project\xslt\" ) in the chunkinfo ???

Please let me know what need to change. I appreciate your help

LVL 26

Accepted Solution

rdcpro earned 500 total points
ID: 9616777
I think you need the base attribute like:

<chunkinfo url="whidata0.xml" base="C:\Source\GroupOne\whxdata\" first="1-800-829-3676" last="10-day" num="102" />

I haven't tried this previously myself, so I'm not completely sure this will solve your problem.  The problem with the document() function is that is an XSLT function (not part of XPath) and how it is handled depends on the XSLT processor.  Read the information in this link, and it should give you some more information.

Mike Sharp
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.


Author Comment

ID: 9616865
Hello Mike,

I modified the xslt and the main xml with the above changes you mentioned.

I am still getting this error

file:/c:/Project/xslt/index_sort.xsl; Line #8; Column #59; Can not load requested doc: c:\c:\Project\xslt\Source\GroupOne\whxdata\whidata0.xml (The filename, directory name, or volume label syntax is incorrect)

thank you,

Author Comment

ID: 9616985
Hello mike,

if you notice, in the error

file:/c:/Project/xslt/index_sort.xsl; Line #8; Column #59; Can not load requested doc: c:\c:\Project\xslt\Source\GroupOne\whxdata\whidata0.xml (The filename, directory name, or volume label syntax is incorrect)

from the above error, notice this part


This path is   c:\Project\xslt\ inserted inbetween

c:\    and   Source\GroupOne\whxdata\whidata0.xml

How its happening.

I saw your last post, I will take a look at the link you provided. Let me know if you have any clue why its happending.

thank you,
LVL 26

Expert Comment

ID: 9616994
This might be a limitation of your XSLT processor.  It looks like even if you give it a base URI, it still wants to go relative to the XSLT...

The .NET parser has a new way of dealing with this issue, because there are potential security issues involved if an XSLT can access resources like this.  But your processor might not even implement it.  I forget what parser/xslt processor you're using...  Can you find out from it's documentation how it handles the document() function?

Mike Sharp

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question