I am having a xml file as input to the xsl file. When i am specifying the outputmethod of xsl as xml and defining an element using xsl:element or matching an element from the xml as said in the other threads i am not getting any tags.I am getting only the text of the xml.I have tried various examples. Whatever i tried i am getting only the text part of the xml. Can you give me a simple example that contains full working code of transforming one xml into another xml using xsl.
Sorry for not posting the sample.
I tried restructuring of xml in two ways:
1) Having an xsl and xml file in the same folder and opening the xml using the browser.The xsl file is applied to the xml as below.
test.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="sample.xsl"?>
<root>
<info>
<firstname>Bob</firstname>
<lastname>Joe</lastname>
</info>
<notes>
<note>text1</note>
<note>text2</note>
</notes>
<othernotes>
<note>text3</note>
<note>text4</note>
</othernotes>
</root>
sample.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root">
<root>
<xsl:copy-of select="info"/>
<notes>
<xsl:copy-of select="othernotes"/>
</notes>
</root>
</xsl:template>
</xsl:stylesheet>
output:
Bob Joe text3 text4
Both the files are in the same folder and i opened the xml file using the browser to see the output.
2)In am using struts framework with xslt in my project. The xml set to the view is as follows.
XML:
<root>
<data>
<array-list>
<array-list xsi:type="java:java.util.ArrayList">
<slot-info-object avail-crit-thresh="-1.0" avail-fif-min="-1.0" avail-five-min="-1.0" avail-one-day="0.0" avail-one-hr="-1.0" avail-warn-thresh="-1.0" freeslot="0" keyn-service-subtype-id="9" perf-crit-thresh="-1.0" perf-fif-min="-1.0" perf-five-min="-1.0" perf-one-day="0.0" perf-one-hr="-1.0" perf-warn-thresh="-1.0" severity-type="0" shared-script-id="-1" slot-id="671457" trans-id="733299" user-id="0" xsi:type="java:com.keynote.mykeynote.service.dashboard.SlotInfoObject">
<slot-alias>Single slot</slot-alias>
</slot-info-object>
<slot-info-object avail-crit-thresh="-1.0" avail-fif-min="1.0" avail-five-min="1.0" avail-one-day="1.0" avail-one-hr="1.0" avail-warn-thresh="-1.0" freeslot="0" keyn-service-subtype-id="9" perf-crit-thresh="-1.0" perf-fif-min="0.5105" perf-five-min="0.529" perf-one-day="0.6195208333333333" perf-one-hr="0.5505" perf-warn-thresh="-1.0" severity-type="0" shared-script-id="595" slot-id="685397" trans-id="-7105" user-id="0">
<slot-alias>SharedSlot</slot-alias>
</slot-info-object>
</array-list>
</array-list>
</data>
</root>
The view is the xsl file that contains the following code:
XSL File:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/root/data/array-list/array-list">
<root>
<slot-info-object>
<xsl:for-each select="slot-info-object">
<xsl:copy-of select="slot-alias"/>
</xsl:for-each>
</slot-info-object>
</root>
</xsl:template>
</xsl:stylesheet>
output:
Single slotSharedSlot
One more Question:
request.setAttribute(StrutsCXConstants.XML_KEY, data);
Here data is the java collection like ArrayList. THis line is written in the struts Action file.This is only converted to the xml for the view.
When we are saying this in the xsl
<xsl:output method="xml" indent="yes"/>
should the response type in the Struts Action class must be set to “text/xml”
Thanks.
In my second case, I got the text because i didn’t set the response type to xml in my java action class. Once I set that, the xsl displays my own custom tags and the tags in the xml which i sent to the xsl.
Regarding my first case, as Dimitre Novatchev said we have to use some command like the one given in the following link.
http://www.biglist.com/lists/xsl-list/archives/199912/msg00082.html
Thanks all for ur info.