Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to execute transformation of multiple files within a subdirectory

Posted on 2013-05-25
5
Medium Priority
?
1,016 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

636 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