What you use is the XSLT transform, which by default is converted to element texts.
Using the same method, you need your own "style sheet":
InputStream xsltIn = StoreData.class.getResourceAsStream("/employees.xslt"); StreamSource xslt = new StreamSource(xsltIn); ///StreamSource xslt = new StreamSource(".../employees.xslt"); Transformer tFormer = TransformerFactory.newInstance().newTransformer(xslt);
Above, I used the resource, not the file system file, so it is packed with the application.
employees.xslt:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/Personnel"> Personnel: <xsl:apply-templates select="./*"/> End personnel. </xsl:template> <xsl:template match="Employee"> * Employee:<xsl:apply-templates select="./@*|./*"/> </xsl:template> <xsl:template match="Name|Id|Age|@type"> - <xsl:value-of select="name()"/>: <xsl:value-of select="."/> </xsl:template> </xsl:stylesheet>
What will create:
Personnel: * Employee: - type: permanent - Name: Seagull - Id: 3674 - Age: 34 * Employee: - type: contract - Name: Robin - Id: 3675 - Age: 25 * Employee: - type: permanent - Name: Crow - Id: 3676 - Age: 28 End personnel.
Joop eggen
source share