I realise that I will probably regret asking about this for the rest of my life, but... Is there some way of applying XSLT to an XML file without the XML file havin
Is there some way of applying XSLT to an XML file without the XML file having an explicit reference to the XSLT file?
Of course. In fact the XSLT specification doesn't rely (mention) at all on the XML file having a reference to the XSLT stylesheet to process it.
Thus it is possible for the same XML file to be processed by many, different XSLT transformations.
In XSLT 2.0 and up it isn't even required for an XSLT transformation to have a corresponding XML document to be applied upon.
How this can be done?
The short answer: This is implementation dependent -- read the corresponding XSLT processor documentation (e.g. XslCompiledTransform for .NET, Saxonica for Saxon, ..., etc).
Also, almost every XSLT processor has a command-line utility for invoking the transformation from the console window -- again check the respective documentation (msxsl.exe for MSXML, nxslt.exe for XslCompiledTransform, ..., etc.)
Here are some comannd-lines for XSLT processors I am using:
This invokes the MSXML 3 processor:
msxsl.exe %xml% %xsl% -o %out% -u '3.0' -t %param[ name="value"]%
This invokes the MSXML 4 processor:
msxsl.exe %xml% %xsl% -o %out% -u '4.0' -t %param[ name="value"]%
This invokes the MSXML 6 processor:
msxsl.exe %xml% %xsl% -o %out% -u '6.0' -t %param[ name="value"]%
This invokes .NET XslCompiledTransform:
nxslt2.exe %xml% %xsl% -t -o %out% %param[ name="value"]%
This invokes AltovaXML (XML-SPY) for XSLT 10:
AltovaXML.exe -xslt1 %xsl% -in %xml% -out %out%%param[ name="value"]%
This invokes AltovaXML (XML-SPY) for XSLT 2.0:
AltovaXML.exe -xslt2 %xsl% -in %xml% -out %out%%param[ name="value"]%
This invokes Saxon 9.x (for XSLT 2.0):
java.exe -Xms512M -Xmx512M -jar C:\xml\Parsers\Saxon\Ver.9.1.0.5\J\saxon9.jar -t -repeat:1 -o %out% %xml% %xsl% %param[ name=\"value\"]%
This invokes XQSharp (XSLT 2.0):
XSLT.exe -s %xml% -o %out% -r 1 -t %xsl% %param[ name="value"]%
In all of the above, %xml% is the path to the XML file, %xsl% is the path to the primary XSLT file, %out% is the path to the file that will contain the output from the transformation.
%param[ name="value"]% is a list of name = value parameter specifications and this isn't mandatory to use.