XSLT remove source's stylesheet
xml, xslt
Solution
Anything starting `<?` (other then the `<?xml version=...?>` declaration) is a processing instruction, which you can match with a pattern of `processing-instruction('name')` (for a specific `<?name ...?>`) or just `processing-instruction()` (for any PI, regardless of name, the same way you would use `*` for any element node):
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="processing-instruction('xml-stylesheet')"/>
<xsl:template match="TestCase">
... remainder of file
Problem
I have my XSLT working, except I can't get it to remove (to not copy, to delete) the source file's `<?xsl-stylesheet...` element/directive. Here's what I have for my XSLT: ``` <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"> <xsl:output method="xml" indent="yes"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="xsl:stylesheet"/> <xsl:template match="TestCase"> ... remainder of file ``` I've tried it with and without a `"?"`, with and without the `"xsl:"` portion in the match attribute, no luck. (So, I've tried the "match" being `"xsl:stylesheet"`, `"?xsl:stylesheet"`, `"stylesheet"`.) The xml source starts off like this: ``` <?xml version="1.0" encoding="UTF-8" standalone="no" ?> <?xml-stylesheet type="text/xsl" href="../../testUtil testLogToHtmlDisplay.xsl" ?> <TestSuite Name="APIC2EChartAddRoute"> ``` TIA.