1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:row="http://www.ibm.com/xmlns/atom/content/datarow/1.0"> <xsl:template match="atom:feed"> <xsl:copy> <!-- copy all nodes outside of "entry" --> <xsl:copy-of select="node()[not(self::atom:entry)]"/> <!-- processing entries --> <xsl:for-each select="//atom:entry"> <!-- filtering --> <xsl:if test="atom:content/row:row/row:Customer_Name = 'Ford'"> <xsl:copy> <xsl:copy-of select="node()"/> </xsl:copy> </xsl:if> </xsl:for-each> </xsl:copy> </xsl:template> </xsl:stylesheet> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | package xml.xslt; import java.io.InputStream; import java.io.OutputStream; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; public class XSLTFilterFeed implements main.IFilterFeed{ public OutputStream filter(InputStream is, String xpathExpr){ OutputStream os = System.out; try{ //create input xml stream source StreamSource transrormSource = new StreamSource(is); // create stylesheet stream source InputStream xsl = XSLTFilterFeed.class.getResourceAsStream("filter.xsl"); Source styleSource = new StreamSource(xsl); //new transformer Transformer transformer = TransformerFactory.newInstance().newTransformer(styleSource); //create output stream result StreamResult transformedResult = new StreamResult(os); //perform transformation transformer.transform(transrormSource, transformedResult); } catch(Exception ex){ ex.printStackTrace(); } return os; } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |