How to generate XML from XSL using Another XML.
843834Mar 28 2003 — edited Mar 28 2003Hello XML Gurus,
I have a requirement where I have an xml file
<?xml:stylesheet type="text/xsl" href=CaseNotes.xsl"?>
<?xml version="1.0" encoding="UTF-8"?>
<employee>
<ssn>1234</ssn>
<fname>kumar></fname>
</employee>
I need to build this xml using the above xml.
<?xml version="1.0" encoding="UTF-8" ?>
<case>
<employeessn>5678</employeessn>
<employeename>myname</employeename>
<case>
I wrote this xsl(CaseNotes.xsl) that takes the 1st xml and tranforms it into the 2nd.
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="employee">
<![CDATA[
<case>
<employeessn>
]]>
<xsl:value-of select="employee/ssn"/>
<![CDATA
</employeessn>
<employeename>
]]>
<xsl:value-of select="employee/fname"/>
<![CDATA
</employeename>
</case>
]]>
</xsl:template>
I included CaseNotes.xml if my first XML. When I see this xml in the browser I could see the generated 2nd XML perfectly. But when use Java code to transform this code I see
& lt; case & gt;
& lt;employeessn &g t; 5678 & lt;/employeessn & gt;
& lt;employeenamemyname & lt;/employeename& gt;
& lt;case& gt ;
Please help me. Is there a way to generate pure xml out of xml? Remember this new xml is with totally new tags.
Transformer transformer;
TransformerFactory factory=TransformerFactory.newInstance();
String fileNamexsl="AddCaseNotesxsl.xsl";
String wipbinxsl=new String();
transformer = factory.newTransformer(new StreamSource(CaseNotes.xsl"));
StringReader sr=new StringReader(sb.toString()); //1st xml
SAXReader xmlReader = new SAXReader();
Document doc = xmlReader.read(sr);
DocumentSource dSource = new DocumentSource(doc);
transformer.transform(dSource,new StreamResult(2ndxml.xml"));
2ndxml appears with & lt;& gt; instead of < and >.
<xsl:value-of select="employee" disable-output-escaping="yes">
I tried using this but is not working.
Is there a solution for this?? Please help me.
Thank you.