I have requirement to convert the xml document to InDesign tag file. Indesign Tags do not have end tags . So I am doing recursive replacements of existing element tags and some transformations on data with indesign acceptable styling conventions. In final step ,I am converting the document to string using xdmp:quote() function. However, since the Indesign tags are concatenated as strings with data,I got the following output. Later i will remove the end tag elements and namespaces using replace function
Note: I am converting to string since i need to produce the plain/text file. Two things i am eager to know Why xdmp:quote is not treating the string "as it is " and how would i solve this solution. Any thoughts or suggestions would be really helpful.
Current-Output
<CharStyle:Italic xmlns:CharStyle="http://www.Charstyle.indesign.com">
funxtx com <CharStyle:>Jan 15 2010 </CharStyle:Italic>
Expected output:
<CharStyle:Italic xmlns:CharStyle="http://www.Charstyle.indesign.com">
funxtx com <CharStyle:>Jan 15 2010 </CharStyle:Italic>
Code:
declare namespace CharStyle = "http://www.Charstyle.indesign.com";
declare namespace cPosition = "http://www.cPosition.indesign.com";
let $book := <Book>
<Author>Priscilla </Author>
<Title>Xquery </Title>
<Source>funxtx com Jan 15 2010</Source>
<year>1990</year>
<release-date>2018-01-01</release-date>
</Book>
let $transformed-book :=
cts:element-walk(
$book,
(xs:QName("Source"),xs:QName("Title"),
xs:QName("year"),xs:QName("release-date")
),
(
if(fn:local-name($cts:node) = "Source")then
let $Source := xdmp:quote($cts:node/text())
let $transformed-text:=
if(fn:matches($Source,"(.*\s*?)(\w{3}\s*\d{2}\s*\d{4})"))then
let $date-transform:= fn:replace($Source,"(.*\s*?)(\w{3}\s*\d{2}\s*\d{4})","$1<CharStyle:>$2")
return $date-transform
else $cts:node/text()
return element{xs:QName("CharStyle:Italic")}{$transformed-text}
else if(fn:local-name($cts:node) = "year")then element{xs:QName("CharStyle:Italic")}{$cts:node/text()}
else if(fn:local-name($cts:node) = "release-date")then element{xs:QName("cPosition:Superscript")}{fn:concat($cts:node/text(),"<cPosition:>")}
else if (fn:local-name($cts:node) = "Title")then element{xs:QName("cPosition:Subscript")}{fn:concat($cts:node/text(),"<cPosition:>")}
else()
)
)
let $string-doc := xdmp:quote($transformed-book)
return $string-doc