Displaying transformed XML into JEditorPane

Tuesday, 10 July 2012 · 5 messages · last reply 11 Jul 2012
SY
Sandeep Yohans10 Jul 2012 06:31 #
Hello, Below is the code to transform XML file to HTML. When tried with BaseX working fine.
let $in := /Resumes/Resume[WorkExpr/Java > "5"]

let $style := doc('resume.xslt')
return (xslt:transform($in, $style)) *The aobve XSLT file will tramsform the output to HTML.* *Now I want to display this HTML output in JEditorPane.* * * **
-- Thanks and Regards Sandeep Yohans
CG
Christian Grün11 Jul 2012 12:39 #
Dear Sandeep, there is no simple general answer to your question, so I'd be glad to if you could prepare a little example [1] that demonstrates the problem. It often takes some time to generate a good and minimized example, but it's often helpful for other readers, too. Thanks in advance (and sorry for all the wise instructions ;), Christian [1] http://mindprod.com/jgloss/sscce.html
Quoted text · Sandeep Yohans · 33 lines
On Tue, Jul 10, 2012 at 6:31 AM, Sandeep Yohans <sandeepy.air at gmail.com> wrote: > Hello, > > Below is the code to transform XML file to HTML. When tried with BaseX > working fine. > > > > let $in := /Resumes/Resume[WorkExpr/Java > "5"] > > let $style := doc('resume.xslt') > > return (xslt:transform($in, $style)) > > > > The aobve XSLT file will tramsform the output to HTML. > > Now I want to display this HTML output in JEditorPane. > > > > > -- > Thanks and Regards > > Sandeep Yohans > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
DK
Dirk Kirsten11 Jul 2012 12:49 #
By mistake I answered privately to Sandeep, so for the sake of documentation here is my answer as well on the mailing list. ---------- Forwarded message ----------
Quoted text · Dirk Kirsten · 46 lines
From: Dirk Kirsten <dk at basex.org> Date: Wed, Jul 11, 2012 at 8:45 AM Subject: Re: [basex-talk] Displaying transformed XML into JEditorPane To: Sandeep Yohans <sandeepy.air at gmail.com> Dear Sandeep, I don't see how your question relates to BaseX? If the transformation is working fine and you have well-formed HTML output, then the rest is up to the application. Seems like you want to do some Swing-programming; displaying HTML in JEditorPane should work out-of-the-box, but please have a look at the Java-API, e.g.: http://docs.oracle.com/javase/7/docs/api/javax/swing/JEditorPane.html Cheers, Dirk On Tue, Jul 10, 2012 at 6:31 AM, Sandeep Yohans <sandeepy.air at gmail.com>wrote: > Hello, > > Below is the code to transform XML file to HTML. When tried with BaseX > working fine. > > > > let $in := /Resumes/Resume[WorkExpr/Java > "5"] > > let $style := doc('resume.xslt') > > return (xslt:transform($in, $style)) > > > > *The aobve XSLT file will tramsform the output to HTML.* > > *Now I want to display this HTML output in JEditorPane.* > > * * > ** > -- > Thanks and Regards > > Sandeep Yohans > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >
AA
Anand Chiney (AIR)11 Jul 2012 13:50 #
Dear Christian, Yes there is SIMPLE GENERAL answer to the question asked by Sandeep. :-) Actually we are storing thousands of resumes in BaseX. These are stored as a single XML document with following format.
<Resumes>

            <Resume>No 1</Resume>

            <Resume>No 2</Resume>

            <Resume>No </Resume>

            <Resume>No 4</Resume>

            <Resume></Resume>

<Resumes>
There are various child elements for <Resume>, which I think is not essential for this generalized answer. Till now I had explained about the Data. Now coming to front-end. We are using Swing based application to search and view these resumes. We want to display the resumes one-by-one in JEditorPane. For this we first transformed the XML to HTML using a XSLT. The BaseX editor can do this using XSLT Module. Christian, do you remember that, earlier there were 3 examples on this and we faced trouble using them. You then corrected these and it helped us a lot, But these were to work with BaseX editor. We need to perform this transformation using Java. Yesterday, Sandeep asked the question on this. We did found a good solution in these 2 examples, here https://github.com/BaseXdb/basex/blob/master/src/test/java/org/basex/test/qu ery/func/FNXsltTest.java https://github.com/BaseXdb/basex/blob/master/src/test/java/org/basex/test/qu ery/AdvancedQueryTest.java But this was not exactly what we were looking for. We need to modify this as per our requirement. And we did it :-) I am not going into deep to explain how we did and why due to less time. Rather I would simply paste the method which worked for us. ----------------------------- Method from the above Example (FNXsltTest.java )------------------------------------------------------------
@Test
  public void xsltTransform() {
    check(_XSLT_TRANSFORM);

    final String doc = "<a/>";
    String style = wrap("<xsl:template match='/'><X/></xsl:template>");
    query(_XSLT_TRANSFORM.args(doc, style), "<X/>");
    query(_XSLT_TRANSFORM.args(doc, '"' + style + '"'), "<X/>");

    style = wrap("<xsl:param name='t'/><xsl:template match='/'>" +
      "<X><xsl:value-of select='$t'/></X></xsl:template>");
    final String param =
      "<xslt:parameters><xslt:t>1</xslt:t></xslt:parameters>";

    query(_XSLT_TRANSFORM.args(doc, style, param), "<X>1</X>");
  }
---------------------------------------------------------------------------- ---------------------------------------------------------------------------- ---------------- ----------------------------- Our Method ------------------------------------------------------------
public String xsltTransform()

{
return query(_XSLT_TRANSFORM.args(getDoc(), getStyleSheet())); } Explanation- getDoc() will send the query which will retrieve the required Resumes based on user search getStyleSheet() for resume.xslt
let $in := /Resumes/Resume[WorkExpr/Java > "5"]
let $style := doc('resume.xslt')
return  (xslt:transform($in, $style))
---------------------------------------------------------------------------- ---------------------------------------------------------------------------- ---------------- ----------------------------- Method from the above Example (AdvancedQueryTest.java)------------------------------------------------- protected static String query(final String query)
{
final QueryProcessor qp = new QueryProcessor(query, CONTEXT); qp.ctx.sc.baseURI("."); try
        {
return qp.execute().toString(); } catch (QueryException ex)
        {
Logger.getLogger(DBTransform.class.getName()).log(Level.SEVERE, null, ex); return ex.getMessage(); } } We used this method as it is rather copy and paste Other methods after certain R&D, we found not useful in our case (!!) ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- ---------------- So wrote a class with these 2 methods (for transformation) and other methods which were useful and it did work. But with a little trouble. This piece of code is NOT PRESERVING THE SPACES which we are giving through our stylesheet. Now for this either you can help us or we need to find a way out of it. Thanks for your kind and timely help. And we will trouble you more in future ;) Regards Anand Chiney _____
Quoted text · Sandeep Yohans · 60 lines
From: Sandeep Yohans [mailto:sandeepy.air at gmail.com] Sent: Wednesday, July 11, 2012 4:24 PM To: Anand Chiney Subject: Fwd: [basex-talk] Displaying transformed XML into JEditorPane ---------- Forwarded message ---------- From: Christian Grün <christian.gruen at gmail.com> Date: Wed, Jul 11, 2012 at 4:09 PM Subject: Re: [basex-talk] Displaying transformed XML into JEditorPane To: Sandeep Yohans <sandeepy.air at gmail.com> Cc: basex-talk at mailman.uni-konstanz.de Dear Sandeep, there is no simple general answer to your question, so I'd be glad to if you could prepare a little example [1] that demonstrates the problem. It often takes some time to generate a good and minimized example, but it's often helpful for other readers, too. Thanks in advance (and sorry for all the wise instructions ;), Christian [1] http://mindprod.com/jgloss/sscce.html On Tue, Jul 10, 2012 at 6:31 AM, Sandeep Yohans <sandeepy.air at gmail.com> wrote: > Hello, > > Below is the code to transform XML file to HTML. When tried with BaseX > working fine. > > > > let $in := /Resumes/Resume[WorkExpr/Java > "5"] > > let $style := doc('resume.xslt') > > return (xslt:transform($in, $style)) > > > > The aobve XSLT file will tramsform the output to HTML. > > Now I want to display this HTML output in JEditorPane. > > > > > -- > Thanks and Regards > > Sandeep Yohans > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > -- Thanks and Regards Sandeep Yohans Software Developer Systems - AIR Infotech Nagpur - India www.airinfotech.in <http://www.airinfotech.in/> Mobile: +91-997-086-5520
CG
Christian Grün11 Jul 2012 17:42 #
Hi Anand, sorry for persisting, but once again I'd like to ask you for a simple, self-contained, compilable example that demonstrates the problem and runs out of the box. Thanks in advance. Christian
Quoted text · Anand Chiney (AIR) · 308 lines
On Wed, Jul 11, 2012 at 1:50 PM, Anand Chiney (AIR) <anandc.air at gmail.com> wrote: > Dear Christian, > > > > Yes there is SIMPLE GENERAL answer to the question asked by Sandeep. J > > > > Actually we are storing thousands of resumes in BaseX. These are stored as a > single XML document > > with following format. > > > > <Resumes> > > <Resume>No 1</Resume> > > <Resume>No 2</Resume> > > <Resume>No </Resume> > > <Resume>No 4</Resume> > > <Resume>……</Resume> > > <Resumes> > > > > There are various child elements for <Resume>, which I think is not > essential for this generalized answer. > > > > Till now I had explained about the Data. Now coming to front-end. We are > using Swing based application > > to search and view these resumes. We want to display the resumes one-by-one > in JEditorPane. > > > > For this we first transformed the XML to HTML using a XSLT. The BaseX editor > can do this using XSLT Module. > > Christian, do you remember that, earlier there were 3 examples on this and > we faced trouble using them. You then > > corrected these and it helped us a lot, But these were to work with BaseX > editor. We need to perform this > > transformation using Java. Yesterday, Sandeep asked the question on this. > > > > We did found a good solution in these 2 examples, here – > > https://github.com/BaseXdb/basex/blob/master/src/test/java/org/basex/test/query/func/FNXsltTest.java > > https://github.com/BaseXdb/basex/blob/master/src/test/java/org/basex/test/query/AdvancedQueryTest.java > > > > But this was not exactly what we were looking for. We need to modify this as > per our requirement. And we did it J > > I am not going into deep to explain how we did and why due to less time. > Rather I would simply paste the method > > which worked for us. > > > > ----------------------------- Method from the above Example (FNXsltTest.java > )------------------------------------------------------------ > > @Test > > public void xsltTransform() { > > check(_XSLT_TRANSFORM); > > > > final String doc = "<a/>"; > > String style = wrap("<xsl:template match='/'><X/></xsl:template>"); > > query(_XSLT_TRANSFORM.args(doc, style), "<X/>"); > > query(_XSLT_TRANSFORM.args(doc, '"' + style + '"'), "<X/>"); > > > > style = wrap("<xsl:param name='t'/><xsl:template match='/'>" + > > "<X><xsl:value-of select='$t'/></X></xsl:template>"); > > final String param = > > "<xslt:parameters><xslt:t>1</xslt:t></xslt:parameters>"; > > > > query(_XSLT_TRANSFORM.args(doc, style, param), "<X>1</X>"); > > } > > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ > > > > ----------------------------- Our Method > ------------------------------------------------------------ > > public String xsltTransform() > > { > > return query(_XSLT_TRANSFORM.args(getDoc(), getStyleSheet())); > > } > > > > Explanation- > > getDoc() will send the query which will retrieve the required Resumes based > on user search > > getStyleSheet() for resume.xslt > > > > let $in := /Resumes/Resume[WorkExpr/Java > "5"] > let $style := doc('resume.xslt') > return (xslt:transform($in, $style)) > > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ > > > > ----------------------------- Method from the above Example > (AdvancedQueryTest.java)------------------------------------------------- > > protected static String query(final String query) > > { > > final QueryProcessor qp = new QueryProcessor(query, CONTEXT); > > qp.ctx.sc.baseURI("."); > > try > > { > > return qp.execute().toString(); > > } > > catch (QueryException ex) > > { > > Logger.getLogger(DBTransform.class.getName()).log(Level.SEVERE, > null, ex); > > return ex.getMessage(); > > } > > } > > > > > > We used this method as it is… rather copy and paste > > Other methods after certain R&D, we found not useful in our case (!!) > > > > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ > > > > > > So wrote a class with these 2 methods (for transformation) and other methods > which were useful and it > > did work. But with a little trouble. This piece of code is NOT PRESERVING > THE SPACES which we are > > giving through our stylesheet. Now for this either you can help us or we > need to find a way out of it. > > > > > > Thanks for your kind and timely help. And we will trouble you more in future > ;) > > > > > > Regards > > Anand Chiney > > > > > > ________________________________ > > From: Sandeep Yohans [mailto:sandeepy.air at gmail.com] > Sent: Wednesday, July 11, 2012 4:24 PM > To: Anand Chiney > Subject: Fwd: [basex-talk] Displaying transformed XML into JEditorPane > > > > > > ---------- Forwarded message ---------- > From: Christian Grün <christian.gruen at gmail.com> > Date: Wed, Jul 11, 2012 at 4:09 PM > Subject: Re: [basex-talk] Displaying transformed XML into JEditorPane > To: Sandeep Yohans <sandeepy.air at gmail.com> > Cc: basex-talk at mailman.uni-konstanz.de > > > Dear Sandeep, > > there is no simple general answer to your question, so I'd be glad to > if you could prepare a little example [1] that demonstrates the > problem. It often takes some time to generate a good and minimized > example, but it's often helpful for other readers, too. > > Thanks in advance (and sorry for all the wise instructions ;), > Christian > > [1] http://mindprod.com/jgloss/sscce.html > _____________________________ > > > On Tue, Jul 10, 2012 at 6:31 AM, Sandeep Yohans <sandeepy.air at gmail.com> > wrote: > >> Hello, >> >> Below is the code to transform XML file to HTML. When tried with BaseX >> working fine. >> >> >> >> let $in := /Resumes/Resume[WorkExpr/Java > "5"] >> >> let $style := doc('resume.xslt') >> >> return (xslt:transform($in, $style)) >> >> >> >> The aobve XSLT file will tramsform the output to HTML. >> >> Now I want to display this HTML output in JEditorPane. >> >> >> >> >> -- >> Thanks and Regards >> >> Sandeep Yohans >> > >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> > > > > > -- > > Thanks and Regards > > Sandeep Yohans > Software Developer > > Systems - AIR Infotech > Nagpur - India > www.airinfotech.in > Mobile: +91-997-086-5520 > >

⚡Generated with XQuery