XSLT

A

ak

Hi-

Is it possible to use XSLT (e.g. using xslLsort and xsl:eek:utput), to
output/write a sorted XML file? Don't want an HTML browser rendering,
need a sorted XML file.

Thanks.

ak
 
M

Martin Honnen

ak said:
Is it possible to use XSLT (e.g. using xslLsort and xsl:eek:utput), to
output/write a sorted XML file? Don't want an HTML browser rendering,
need a sorted XML file.

Yes, no problem, XSLT transforms in input tree into a result tree and
then optionally allows serializing that result tree as either html or
xml or text so of course you can use XSLT to transform XML to some
sorted XML, use
<xsl:eek:utput method="xml" />
and then write your templates to sort the XML input the way you want.
 
A

ak

Thanks for your reply.

I've a doubt about getting the sorted XML. I'd still need a browser to
view sorted results. Instead I need to get a sorted XML file (i.e.
write to a new xml file). Is there a way to do that?

Alternatively, of all the ways I've seen to manipulate a DOM tree, I
couldn't figure out how I could dump a (sorted??) tree to XML file,
either after sorting it in memory, or applying some kind of
transformation while writing a file like that (using
javax.xml.Transform)!!

What I really need is to find the best way to take an XML file and
output another XML in which elements are sorted something like this-

(original fragment)
<action path="/StartLogin" forward="/Login.do"/>
<action path="/Login"
className="oracle.adf.controller.struts.actions.DataActionMapping"
type="oracle.adf.controller.struts.actions.DataForwardAction"
name="DataForm" parameter="/login.uix">
<set-property property="modelReference"
value="MemInfoUIModel"/>
<forward name="success" path="/Main.do?node_id=ED"/>
<forward name="failure" path="/Login.do?badlogin=1"/>
<forward name="disabled" path="/Login.do?badlogin=2"/>
</action>


Above is the original fragment.
If we say (in the configuration) order all 'action' tags by the 'path'
attribute and all 'forward' tags by 'name' I would expect the result
to look like this:

<action path="/Login"
className="oracle.adf.controller.struts.actions.DataActionMapping"
type="oracle.adf.controller.struts.actions.DataForwardAction"
name="DataForm" parameter="/login.uix">
<forward name="disabled" path="/Login.do?badlogin=2"/>
<forward name="failure" path="/Login.do?badlogin=1"/>
<forward name="success" path="/Main.do?node_id=ED"/>
<set-property property="modelReference"
value="MemInfoUIModel"/>
</action>
<action path="/StartLogin" forward="/Login.do"/>

(action tags are sorted by 'path' value and forward tags are sorted by
'name' values)

It's a big struts-config file which I'm trying to sort. Please don't
ask me why!! :))

Thanks.

ak
 
M

Martin Honnen

ak said:
I've a doubt about getting the sorted XML. I'd still need a browser to
view sorted results. Instead I need to get a sorted XML file (i.e.
write to a new xml file). Is there a way to do that?

Where does the XSLT or XPath specification say anything about browsers?
XSLT is not necessarily done in a browser, there are lots of XSLT
processors outside of browsers. Indeed, browser support for XSLT is
rather poor.

What I really need is to find the best way to take an XML file and
output another XML in which elements are sorted

Then write an XSLT stylesheet that does that (using <xsl:eek:utput
method="xml" /> and <xsl:sort />) and use an XSLT processor that allows
you to serialize to a file.
In JAXP the transform method takes a javax.xml.transform.Result to
transform to and that can be a DOMResult or a SAXResult or a
StreamResult and a StreamResult can be constructed for a File or an
OutputStream.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,850
Latest member
VMRKlaus8

Latest Threads

Top