Reputation: 72
I need to change an attribute to a certain value in several .xml files all at once using one xslt. The filenames all begin with a common phrase and end with a unique number (such as abc01.xml, abc02.xml, abc03.xml, etc.). Is there a way to target a collection of .xml files like this with one xsl transform?
Here is what I've tried so far, which doesn't work:
<?xml version="2.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template select="document(../SavedDashboards/*.xml)" match="Tab/@Caption">
<xsl:attribute name="Caption">Dashboard</xsl:attribute>
</xsl:template>
</xsl:document>
</xsl:stylesheet>
Upvotes: 0
Views: 66
Reputation: 167716
It depends on the XSLT processor you use, for instance Saxon 9 as documented at http://saxonica.com/html/documentation/using-xsl/commandline.html allows you to process a directory of files if you call it as e.g. java -jar saxon9.jar -s:inputDirectoryName -o:outputDirectoryName -xsl:sheet.xsl
. And your stylesheet sheet.xsl
would then simply do
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* , node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Tab/@Caption">
<xsl:attribute name="Caption">Dashboard</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1