Solved

How to execute transformation of multiple files within a subdirectory

Posted on 2013-05-25
5
816 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
ID: 39197065
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
ID: 39197390
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
ID: 39198545
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
ID: 39198665
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
ID: 39210169
I got the answer to this in another forum.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 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