Solved

Transformation path issue

Posted on 2003-10-24
6
379 Views
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){

            try{
                  DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                  DocumentBuilder        docBuilder        = docBuilderFactory.newDocumentBuilder();
            
                  Document mergedDocument = docBuilder.newDocument();
                  Node     indexElement   = mergedDocument.createElement("index");
                  mergedDocument.appendChild(indexElement);
            
                  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);
                              indexElement.appendChild(newChunkInfoNode);
                        }
                  }

                  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){
                  te.printStackTrace();
            }catch(ParserConfigurationException pce){
                  pce.printStackTrace();
            }catch(SAXParseException spe){
                  spe.printStackTrace();
            }catch(SAXException se){
                  se.printStackTrace();
            }catch(IOException ie){
                  ie.printStackTrace();
            }catch(Exception e){
                  e.printStackTrace();
            }
    }

}



Here is the xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <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">
       <!--<mergeddoc>-->
           <indexdata>
               <xsl:apply-templates select="$vDataMerged">
                   <xsl:sort select="@name" order="ascending" data-type="text"/>
               </xsl:apply-templates>
           </indexdata>
       <!--</mergeddoc>-->
   </xsl:template>
   <xsl:template match="/ | node()">
       <xsl:copy>
           <xsl:apply-templates select="@*"/>
           <xsl:apply-templates/>
       </xsl:copy>
   </xsl:template>
   <xsl:template match="text() | @*">
       <xsl:copy/>
   </xsl:template>
</xsl:stylesheet>



Main xml is pointing to the Data file is like below

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

</index>

Data File
---------


<?xml version='1.0' encoding='ISO-8859-1' ?>
<indexdata>
<key name="1-800-829-3676" >
  <key name="calling" >
    <topic name="Chapter 201.1 " url="Manuals/YGKLE/201_1.html" />
  </key>
</key>
<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>
</key>
<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" />
</key>
</indexdata>
0
Comment
Question by:alagappanK
  • 3
  • 3
6 Comments
 
LVL 26

Expert Comment

by:rdcpro
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' ?>
<index>
<chunkinfo url="whidata0.xml" first="1-800-829-3676" last="10-day" num="102" />

</index>

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

Now, the xslt document() function can take two arguments. (see: http://www.w3.org/TR/xslt#document)  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"/>

Regards,
Mike Sharp
0
 

Author Comment

by:alagappanK
ID: 9616630
Hello Mike,

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

<?xml version='1.0' encoding='ISO-8859-1' ?>
<index>
<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">
</index>



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

alagappanK
0
 
LVL 26

Accepted Solution

by:
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.

http://www.w3.org/TR/xslt#document

Regards,
Mike Sharp
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:alagappanK
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,
alagappanK
0
 

Author Comment

by:alagappanK
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

c:\c:\Project\xslt\Source\GroupOne\whxdata\whidata0.xml

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,
alagappanK
0
 
LVL 26

Expert Comment

by:rdcpro
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?

Regards,
Mike Sharp
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

937 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now