?
Solved

How to execute transformation of multiple files within a subdirectory

Posted on 2013-05-25
5
Medium Priority
?
1,073 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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 video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

850 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