Aswanikumar
Aswanikumar

Reputation: 115

xdmp:quote() - Character special strings <,> are converted to < and > in the output

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 &lt;CharStyle:&gt;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                       

Upvotes: 1

Views: 397

Answers (3)

DALDEI
DALDEI

Reputation: 3732

variant on bens answer similar to xhtml. create the non-closing tags as self closing

 <Tag/> 

quote. then string replace note your example tags are not valid xml as the format parses as qname with a empty localname. you can abuse that by using a placeholder similar to bens suggestion

 <Special:REPLACEME/>

then a replace of ":REPLACEME/" -> ":" to avoid having to individually replace all possible tags

alternative -- use xml comments

<!--<Special:>-->

quote then delete all "".

Upvotes: 0

BenW
BenW

Reputation: 433

Think of it like this: your expected output is not valid XML, so it can't be xdmp:unquoted. That implies (although I'm not sure how rigorously) that there is no combination of XML and text that could be xdmp:quoted to achieve the output you want.

One option would be to build some XML that can be quoted to achieve nearly the desired output. e.g. build $transformed-text using valid XML placeholders instead of the real InDesign tags, e.g. <CharStyle:REPLACEME/>. Then after calling xdmp:quote(), do a string replacement for each kind of placeholder you used, e.g. to replace all instances of "<CharStyle:REPLACEME/>" with "<CharStyle:>".

Upvotes: 2

mholstege
mholstege

Reputation: 4912

Specify the output option method to have the value text on the xdmp:quote call.

The brackets are getting escaped because that is the rules for XML output: it wouldn't be valid XML otherwise.

Upvotes: 1

Related Questions