Transformation path issue

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" />
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
alagappanKAuthor Commented:
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

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

alagappanKAuthor Commented:
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,
alagappanKAuthor Commented:
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,
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.