How to remove elements from xml using xslt with stylesheet and xsltproc?

Using one of the most fundamental XSLT design patterns: “Overriding the identity transformation” one will just write the following: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output omit-xml-declaration=”yes”/> <xsl:template match=”node()|@*”> <xsl:copy> <xsl:apply-templates select=”node()|@*”/> </xsl:copy> </xsl:template> <xsl:template match=”Element[@fruit=”apple” and @animal=”cat”]”/> </xsl:stylesheet> Do note how the second template overrides the identity (1st) template only for elements named “Element” that have an … Read more

In what order do templates in an XSLT document execute, and do they match on the source XML or the buffered output?

I love your question. You’re very articulate about what you do not yet understand. You just need something to tie things together. My recommendation is that you read “How XSLT Works”, a chapter I wrote to address exactly the questions you’re asking. I’d love to hear if it ties things together for you. Less formally, … Read more

XML to CSV Using XSLT

Here is a version with configurable parameters that you can set programmatically: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output method=”text” encoding=”utf-8″ /> <xsl:param name=”delim” select=”‘,'” /> <xsl:param name=”quote” select=”‘&quot;'” /> <xsl:param name=”break” select=”‘&#xA;'” /> <xsl:template match=”https://stackoverflow.com/”> <xsl:apply-templates select=”projects/project” /> </xsl:template> <xsl:template match=”project”> <xsl:apply-templates /> <xsl:if test=”following-sibling::*”> <xsl:value-of select=”$break” /> </xsl:if> </xsl:template> <xsl:template match=”*”> <!– remove normalize-space() if you … Read more

XSLT processing with Java?

Here is sample for using java api for transformer, as @Raedwald said: import javax.xml.transform.*; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; public class TestMain { public static void main(String[] args) throws IOException, URISyntaxException, TransformerException { TransformerFactory factory = TransformerFactory.newInstance(); Source xslt = new StreamSource(new File(“transform.xslt”)); Transformer transformer = factory.newTransformer(xslt); Source text = … Read more