I have an XML file and I need to convert it into XQuery. consider a simple set of XML:
books[book]
book[@isbn, title, descrption]
eg:
<books>
<book isbn="1590593049">
<title>Extending Flash MX 2004</title>
<description>
Using javascript alongwith actionscript 3.0 and mxml.</description>
</book>
<book isbn="0132149184">
<title>Java Software Solutions</title>
<description>
Complete book full of case studies on business solutions and design concepts while building mission critical
business applications.
</description>
</book>
How to convert it to CSV format using XQuery? The CSV is used by Microsoft excel,
so it would be delimited by comma (,) character and special characters should be escaped.
A pure XPath 2.0 expression:
XSLT 2 – based verification:
When this transformation is applied on the provided XML document (corrected from its malformedness):
the wanted, correct result is produced:
Update:
In a comment the OP has requested that any in-text comma be surrounded by a quote and that (after that) any quote be replaced by two quotes, and, finally, if the wholw result contains a quote, it must be surrounded by (single) quotes.
Here is a pure XPath 2.0 expression that produces this:
When this XPath expression is evaluated against this (extended with a new test-case) XML document:
the wanted, correct result is produced: