This is presumably an almost carbon copy of Using XSLT as an XML pre-processor But as the OP of that question did not post a full example, despite being asked to, the replies are no use to anyone not familiar with XSLT. Neither have extensive web searches turned up anything helpful - XSLT seems remarkably poorly documented and little discussed on the Web.
Anyway ...
I have an XML file, say foo.xml, as follows (greatly simplified, obviously):
<?xml version="1.0" encoding="UTF-8"?>
<main>
<fee>blah</fee>
<ifdef select="OLD_VERSION">
<fi>blah blah</fi>
</ifdef>
</main>
(C-style #ifdef changed to "ifdef" block in light of Ian Roberts's answer)
I want to run an xsltproc command on linux, as follows:
xsltproc --stringparam xmlver NEW_VERSION --nonet foo.xslt foo.xml
and have this use the following XSLT file, foo.xslt, to exclude the #ifdef'ed section:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" />
<xsl:param name="xmlver" required="yes"/>
<xsl:template match="node() | @*">
<xsl:copy><xsl:apply-templates select="node() | @*"/></xsl:copy>
</xsl:template>
<xsl:variable name="defines" select="document($xmlver)/defines"/>
<xsl:template match="ifdef">
<xsl:variable name="this" select="."/>
<xsl:for-each select="$defines[def = $this/@select]">
<xsl:apply-templates select="$this/node()" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
(I did use the replies to the question referenced above to construct this XSLT; but the missing ingredient is where/how to incorporate the "xmlver" value. Of course there is no guarantee it is correct in the above; but this essentially what I am asking - How is all this put together in a way that works?)
Any constructive replies will be greatly appreciated, and will doubtless be useful to many people with a similar requirement in the future; but please no tiresome, dogmatic "Why would you want to do that?" replies!