XSLT refactoring not working ('A processing instruction must not be named 'xml' …)

Here should go questions about transforming XML with XSLT and FOP.
Vinny
Posts: 16
Joined: Wed Jan 12, 2022 1:07 pm

XSLT refactoring not working ('A processing instruction must not be named 'xml' …)

Post by Vinny »

Hi,
I’m trying to write a lightweight refactoring XSLT stylesheet.
To begin with, I just copied that over from existing stylesheets;

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    xmlns:xr="http://www.oxygenxml.com/ns/xmlRefactoring"
    version="2.0">
    
    <xsl:import href="http://www.oxygenxml.com/ns/xmlRefactoring/resources/commons.xsl"/>
    
    <!-- default copy template -->
    <xsl:template match="node() | @*">
        <xsl:copy>
            <xsl:apply-templates select="node() | @*"/>
        </xsl:copy>
    </xsl:template>
        
</xsl:stylesheet>
So basically, this does nothing. However, when I try to execute it using the Tools → Refactoring dialogue, I always get this fatal error:

‘System ID: /Users/vincent/Documents/DITA/Refactoring/ddtable.xsl
Severity: fatal
Problem ID: XPST0003
Description: A processing instruction must not be named 'xml' in any combination of upper and lower case
Start location: 1:0
URL: http://www.w3.org/TR/xpath20/#ERRXPST0003

Googling that error finds things about Xquery, but I’m not sure to understand how it is related to an XSLT stylesheet, and what to do about it.
Thanks,
Vincent
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: XSLT refactoring not working ('A processing instruction must not be named 'xml' …)

Post by Radu »

Hi Vincent,

I created a folder on disk containing a "refactor.xsl" with your XSLT content and a "refactor.xml" which looks like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<refactoringOperationDescriptor 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.oxygenxml.com/ns/xmlRefactoring" id="some_UNIQUE_ID" name="CUSTOM OPERATION NAME">
    <description>The description of the operation.</description>    
    <script type="XSLT" href="refactor.xsl"/>
</refactoringOperationDescriptor>
Afterwards I used this refactoring action named "CUSTOM OPERATION NAME" on my side on a small XML document and it worked (it preserved the XML exactly as it is and did not report that error).
Maybe this is somehow related to the XML document you want to refactor, is that XML document valid when opened in Oxygen?

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Vinny
Posts: 16
Joined: Wed Jan 12, 2022 1:07 pm

Re: XSLT refactoring not working ('A processing instruction must not be named 'xml' …)

Post by Vinny »

Thanks Radu!
In fact, my descriptor looked like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<refactoringOperationDescriptor 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.oxygenxml.com/ns/xmlRefactoring" 
    id="ddtable" 
    name="Move tables outside of DL">
    <description>Take tables outside of dd elements.</description>    
    <!-- For the XSLT stylesheet option uncomment the following line and comment
           the line referring the XQuery Update script -->
    <!-- <script type="XSLT" href="convert-attribute-to-element.xsl"/> --> 
    <script type="XQUERY_UPDATE" href="ddtable.xsl"/>
</refactoringOperationDescriptor>
I didn't pay attention to the "XQUERY_UPDATE" type, because I dumbly copied that from the online example!

Thanks a bunch for your answer,
Vincent
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: XSLT refactoring not working ('A processing instruction must not be named 'xml' …)

Post by Radu »

Hi Vincent,

Right, it's clear now.
I also created some time ago a free GitHub project with lots of refactoring actions if you find anything interesting there:
https://github.com/oxygenxml/dita-refactoring-examples

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Vinny
Posts: 16
Joined: Wed Jan 12, 2022 1:07 pm

Re: XSLT refactoring not working ('A processing instruction must not be named 'xml' …)

Post by Vinny »

Radu,
thanks a bunch for the pointer. I’ll have a look and pick whatever seems handy :)

Also, how would you put a tag in comment? i.e. transform
<whatever> … </whatever>
into
<!-- <whatever> … </whatever> -->

Thanks!
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: XSLT refactoring not working ('A processing instruction must not be named 'xml' …)

Post by Radu »

Hi Vincent,

It would have been cool if something like this worked:

Code: Select all

<xsl:template match="toRemove">
        <xsl:comment select="."/>
    </xsl:template>
but unfortunately it just saves the plain text content inside the created comment.
This works:
https://stackoverflow.com/questions/192 ... ment-block

Code: Select all

<xsl:text disable-output-escaping="yes">&lt;!--</xsl:text>
<xsl:copy-of select="."/>
<xsl:text disable-output-escaping="yes">--&gt;</xsl:text>
but you may have problems if the serialized XML element contains inside it other XML comments.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Vinny
Posts: 16
Joined: Wed Jan 12, 2022 1:07 pm

Re: XSLT refactoring not working ('A processing instruction must not be named 'xml' …)

Post by Vinny »

Ah, that’s the
disable-output-escaping
part I wasn't familiar with. thanks!

TBH, I’m trying to write a more complex transform, i.e. pulling a <table> element outside its parent <dl> element, but not placing it before or after. Instead, the <dl> element must end before the table, and resume just after. It is a simple matter of inserting </dlentry></dl> before the table and <dl><dlentry> after it, so what you told me is probably going to be enough.

Thanks again,
Vincent

PS: It doesn’t work. I’m getting '&lt;' in the transformed file. But never mind, I just gave up the idea of coding that transformation for the time being. It is quite complex and needs more thought than… I thought :p The solution I wrote above won’t work: I’m left with a dangling </dd> that I must get rid of, and it’s a pain. On the other hand, recreating a whole set of <dd> nodes with their sub-nodes is really a convoluted task.
Post Reply