JAXB, XSLT comparison

S

Sony Antony

We have a situation wherin we should translate the incoming XML based
on one schema to the outgoing XML that is based on another schema.
Since both input and output are both XML, XSLT was the natural
preference.

But there was a requirement that demanded a part of the generated XML
to be different depending on whether an element was present or not in
the incoming XML. Since we were only beginning with XML, we couldn t
find the Xpath xsl:if combination that will generate this logic. ( Can
somebody help me here, though that is not the main topic of this
posting )

So somebody came up with JAXB. We changed the program so that the
incoming XML was converted to Java objects using JAXB. Then there was
the ‘if' statement in java and the result was converted to XML again
using JAXB.
At this time this was thought to be an inefficient ad hoc way of
getting the task done. But then I read more about JAXB and came to
know that JAXB generated code can be as fast as a SAX parser.
Now it appears to me that XSLT might be using DOM parser internally
and that it might be actually slower than the JAXB way.
I know I should do an actual performance comparison to reach any
conclusions. But can somebody theoretically compare which of these
methods will be faster.

Thanks a lot for reading
--sony
 
A

Arto V. Viitanen

Sony> We have a situation wherin we should translate the incoming XML based
Sony> on one schema to the outgoing XML that is based on another schema.
Sony> Since both input and output are both XML, XSLT was the natural
Sony> preference.

Sony> But there was a requirement that demanded a part of the generated XML
Sony> to be different depending on whether an element was present or not in
Sony> the incoming XML. Since we were only beginning with XML, we couldn t
Sony> find the Xpath xsl:if combination that will generate this logic. ( Can
Sony> somebody help me here, though that is not the main topic of this
Sony> posting )

XSLT's xsl:if is not like ifs in general programming languages, since it does
not come with xsl:else. Instead, you should use xsl:choose, like

<xsl:choose>
<xsl:when test="nameoftheelement">
<!-- do what you need with the element -->
</xsl:when>
<xsl:eek:therwise>
<!-- element does not exist, do what is needed -->
</xsl:eek:therwise>
</xsl:choose>
 

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

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,851
Latest member
CliftonCor

Latest Threads

Top