XSLT

Discussion in 'XML' started by ak, Nov 8, 2005.

  1. ak

    ak Guest

    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
     
    ak, Nov 8, 2005
    #1
    1. Advertising

  2. ak wrote:

    > 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.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Nov 9, 2005
    #2
    1. Advertising

  3. ak

    ak Guest

    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
     
    ak, Nov 9, 2005
    #3
  4. ak wrote:

    > 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.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Nov 9, 2005
    #4
  5. ak

    ak Guest

    Thanks Martin.

    That's great help. I'll try that.

    ak
     
    ak, Nov 9, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stylus Studio
    Replies:
    0
    Views:
    738
    Stylus Studio
    Aug 3, 2004
  2. Benjamin Hillsley
    Replies:
    3
    Views:
    1,732
    Dimitre Novatchev
    Sep 25, 2003
  3. ted
    Replies:
    1
    Views:
    648
    Laurens
    Jan 26, 2004
  4. Replies:
    2
    Views:
    735
    Henry S. Thompson
    Oct 19, 2005
  5. Replies:
    4
    Views:
    702
Loading...

Share This Page