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@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@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@gmail.com>
Cc: basex-talk@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@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@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