Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 388
  • Last Modified:

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){

            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
alagappanK
Asked:
alagappanK
  • 3
  • 3
1 Solution
 
rdcproCommented:
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
 
alagappanKAuthor Commented:
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
 
rdcproCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

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
 
rdcproCommented:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now