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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

623 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