Solved

How to execute transformation of multiple files within a subdirectory

Posted on 2013-05-25
5
754 Views
Last Modified: 2013-05-31
I want to transform all the XML files within a subdirectory and output the results to a single XML file. I'm not sure if the XSL below works because I haven't figured out how to execute it.

I tried executing the code below from the command line but it didn't work:

java -jar c:\saxon\saxon9he.jar -s:"C:\Temp\2011 Valid XML" -o:"C:\Temp\LookupTables.xml" -xsl:"C:\Temp\LookupTables.xsl"


Here is the XSL:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:template match="node()|@*" mode="inFile">
                 <xsl:copy>
                      <xsl:apply-templates mode="inFile" select="node()|@*"/>
                 </xsl:copy>
            </xsl:template>
    
    <xsl:template match="/">
        <xsl:apply-templates mode="inFile" select="collection('file:///C:/Temp/2011 Valid XML?select=*.xml;recurse=yes')"/>
        <LookupTables>
            <Facility_Identifiers>
                <xsl:for-each select="/Report/RegistrationData/Facility/Identifiers/IdentifierList">
                    <Facility_Identifier Org="{/Report/RegistrationData/Organisation/Details/BusinessLegalName}" Facility="{/Report/RegistrationData/Facility/Details/FacilityName}" NPRI_ID="{Identifier[IdentifierType = 'NationalPollutantReleaseInventoryId']/IdentifierValue}" GHGIS_ID="{Identifier[IdentifierType = 'GHGRPId']/IdentifierValue}"/>
                </xsl:for-each>
            </Facility_Identifiers>
            <NAICS_Details>
                <xsl:for-each select="/Report/RegistrationData/Facility/Identifiers/NAICSCodeList/NAICSCode">
                    <NAICS_Detail Org="{/Report/RegistrationData/Organisation/Details/BusinessLegalName}" Facility="{/Report/RegistrationData/Facility/Details/FacilityName}" NAICS="{Code}" Classification="{NAICSClassification}" Percentage="{ActivityPercentage}"/>
                </xsl:for-each>
            </NAICS_Details>
        </LookupTables>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

0
Comment
Question by:mariita
  • 3
  • 2
5 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
this is not a valid file uri

"file:///C:/Temp/2011 Valid XML"

I don't think the spaces wil work

try


"file:///C:/Temp/2011%20Valid%20XML"
0
 

Author Comment

by:mariita
Comment Utility
I'm still getting a source file does not exist error.

The above syntax actually works (including spaces in the uri) if both the source uri and the output uri are directories, but it doesn't work if the source uri is a directory while the output uri is a filename. If both the source uri and the output uri are directories, then the XSL is applied to each file in the the source directory, and the output will be a different file, which is written to each uri in the target directory.
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
strange, the source should be a directory, the output a single file on the command line

You can't write to multiple files unless you have an xsl:result-document in there

Can you say what you are doing exactly?
0
 

Accepted Solution

by:
mariita earned 0 total points
Comment Utility
I got the answer to this in another forum.

Saxon 9 does allow writing to multiple files using the syntax:

java -jar SomePath/saxon9he.jar -s:inputDirectory -o:outputDirectory -xsl:sheet.xsl

If the input is a directory and the output is a single file, then the -s: parameter is omitted and replaced with the  -it:mainTemplate command line option, where mainTemplate is the main template in the XSL. Then the mainTemplate pulls in the XML files using the collection function.

java -jar SomePath/saxon9he.jar -it:mainTemplate -o:outputFile -xsl:sheet.xsl

<xsl:template name="mainTemplate">
  <root>
    <xsl:apply-templates select="collection('file:///C:Temp/dir?select=*.xml')/*"/>
  </root>
</xsl:template>

See:
http://www.oxygenxml.com/archives/xsl-list/200911/msg00044.html
and
http://stackoverflow.com/questions/16757759/how-to-execute-xslt-with-multiple-input-files-and-single-output-file
0
 

Author Closing Comment

by:mariita
Comment Utility
I got the answer to this in another forum.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

7 Experts available now in Live!

Get 1:1 Help Now