Read a remote zipped xml with just XSL

后端 未结 5 1619
北海茫月
北海茫月 2020-12-16 08:00

I want to know if it\'s possible for an XSLT file to read data from an XML located within folders of a remote zip(from the server at work), without any external processors (

相关标签:
5条回答
  • 2020-12-16 08:01

    Unless your file system provides a native, transparent way to access a zip file as if it were a folder, this won't be possible.

    In other words: You must be able to open the path you tried to feed to document() in any other program on your system. If that does not work anywhere else, what would make you assume it would work in XSLT?

    0 讨论(0)
  • 2020-12-16 08:01

    From what I got by reading all of your (very quick) responses and since using XSLT alone elicited "probably-not-possible" answers and Saxon-talk, I guess Saxon's the way to go. I'll try it first at home, to see how much of a hassle it is to install/use given that usually whenever I mention installing something at work, they turn me down (I'm an intern). I'll just wait till Martin Honnen answers my comment, though.

    Thank you very much for your time and also for answering so quicky.

    Edit: Thanks Martin, will check the documentation for that feature.

    0 讨论(0)
  • 2020-12-16 08:07

    I just tried the AltovaXML tools command line XSLT 2.0 processor with the following XSLT 2.0 stylesheet:

    <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="2.0">
    
      <xsl:template name="main">
        <xsl:copy-of select="document('ziptest1.zip|zip/ziptest1/file.xml')"/>
      </xsl:template>
    
    </xsl:stylesheet>
    

    where "ziptest1.zip" is a .zip file with a folder named "ziptest1" containing a file named "file.xml" and the output I get is the contents of that file. If the path can't be resolved then I get an error saying "Error retrieving resource".

    I tested that with "AltovaXML Version 2010 rel. 3" which I think is the latest version.

    0 讨论(0)
  • 2020-12-16 08:09

    If you are using Saxon, then you could use the EXPath Zip Facility.

    Here is an example:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
                    xmlns:zip="http://www.expath.org/mod/zip"
                    version="2.0">
    
       <xsl:import href="http://www.expath.org/mod/zip.xsl"/>
    
       <xsl:output indent="yes"/>
    
       <!--
           $file is the ZIP file to use.  If $entry is set, extract that
           entry from $file, as an XML document.  If not, list the content
           of $file.
       -->
       <xsl:param name="file"  as="xs:string"/>
       <xsl:param name="entry" as="xs:string?"/>
    
       <xsl:template name="main" match="/">
          <xsl:choose>
             <xsl:when test="$entry">
                <!-- an XML entry in the ZIP file -->
                <xsl:sequence select="zip:xml-entry($file, $entry)"/>
             </xsl:when>
             <xsl:otherwise>
                <!-- the structure of the ZIP file -->
                <xsl:sequence select="zip:entries($file)"/>
             </xsl:otherwise>
          </xsl:choose>
       </xsl:template>
    
    </xsl:stylesheet>
    
    0 讨论(0)
  • 2020-12-16 08:13

    I don't think there is a general way of doing that.

    However, in many Java-based XSLT processors (at least Saxon and Xalan), you can use 'jar:' URLs to refer to resources inside zip files. Prefix the URL pointing to the zip file with jar: and suffix it with !/ and the path to the file inside it. Like this: jar:file:///the/path/to/foo.zip!/foo.xml.

    To achieve the same in other processors, you would probably need figure out if they allow registering a custom "URI handler" or an equivalent to deal with the special URIs you want to support.

    0 讨论(0)
提交回复
热议问题