Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to generate XML from XSL using Another XML.

843834Mar 28 2003 — edited Mar 28 2003
Hello 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 25 2003
Added on Mar 28 2003
4 comments
239 views