MyNguyen
MyNguyen

Reputation: 339

how to add and remove processing-instruction in xml with xquery

I want to add and remove a processing-instruction as same as

<?xml-stylesheet type="text/xsl" href="OtxViewer.xsl" ?> 

into a xml file with xquery but i cannot. please help me for a solution?

Upvotes: 0

Views: 849

Answers (1)

adamretter
adamretter

Reputation: 3517

To remove the processing instruction you can copy all top-level nodes apart from the processing instruction, for example:

document {
    doc("file:/c:/Untitled1.xml")/node()[not(. instance of processing-instruction(xml-stylesheet))]
}

to add a processing instruction you can insert it in a new document and copy in the top-level nodes from the old document, for example:

document {
    processing-instruction xml-stylesheet {
        'type="text/xsl" href="OtxViewer.xsl"'
    },
    doc("file:/c:/Untitled1.xml")/node()
}

Upvotes: 4

Related Questions