Remove multiline comments

Here should go questions about transforming XML with XSLT and FOP.
msambasiva
Posts: 87
Joined: Tue Jul 17, 2018 6:57 am

Remove multiline comments

Post by msambasiva »

Hi,
We are using XSLT 2.0. We have a requirement to remove multiline comments before displaying the content from a xml.
Need to exclude the '/* bug#22652320' and 'AND PH.TERMS_ID = AT.TERM_ID(+) */' from the below xml content in the output.

Any clue would be great help.
Thanks in advance,
Samba.

Code: Select all

            <query>
                <sql-statement>AND RT.SHIPMENT_LINE_ID = SL.SHIPMENT_LINE_ID</sql-statement>
            </query>
            <query>
                <sql-statement>[b]/* bug#22652320<[/b]</sql-statement>
            </query>
            <query>
                <sql-statement>[b]AND PH.TERMS_ID = AT.TERM_ID(+) */[/b]</sql-statement>
            </query>
            <query>
                <sql-statement>AND RT.VENDOR_ID = VE.VENDOR_ID</sql-statement>
            </query>
            <query>
                <sql-statement>AND RT.vendor_site_id = VS.vendor_site_id</sql-statement>
            </query>
            <query>
                <sql-statement>AND PH.BILLTO_BU_ID = VS.BU_ID</sql-statement>
            </query>
            <query>
                <sql-statement>AND RT.VENDOR_SITE_ID = PSS.VENDOR_SITE_ID</sql-statement>
            </query>
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: Remove multiline comments

Post by Radu »

Hi,

Those are not XML comments (XML comments look like <!--comment text-->) so it's hard to match them using XSLT.
Also you should first check if your XML document is wellformed. On the Oxygen toolbar there is a "Validate" drop-down button which has a "Check Well-Formedness" action. If the action reports problems, then you will not be able to apply XSLT over the XML document.
So in the end you may end up needing to apply a regular expression on the XML document to do what you want.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
msambasiva
Posts: 87
Joined: Tue Jul 17, 2018 6:57 am

Re: Remove multiline comments

Post by msambasiva »

Those are sql comments but not xml comments. Those comments are part of xml content. While parsing xml using xslt, we need to exclude those comments and display the rest of the content.

Ex: Below is the part of xml content having sql-statement child element of query. We need to display only first element content(AP_LOOKUP_CODES ALC1) and last element contents ( WHERE SH.RECEIPT_SOURCE_CODE = 'VENDOR') in a table format.

<query>
<sql-statement> AP_LOOKUP_CODES ALC1 </sql-statement>
</query>
<query>
<sql-statement>/* Commented for bug#22652320</sql-statement>
</query>
<query>
<sql-statement> FND_LOOKUPS PLC ,</sql-statement>
</query>
<query>
<sql-statement> PO_LOOKUP_CODES PLC1 ,</sql-statement>
</query>
<query>
<sql-statement> AP_LOOKUP_CODES ALC2 , </sql-statement>
</query>
<query>
<sql-statement> AP_LOOKUP_CODES ALC */ </sql-statement>
</query>
<query>
<sql-statement> WHERE SH.RECEIPT_SOURCE_CODE = 'VENDOR'</sql-statement>
</query>

I thought of using Regex. But I don't get any clue. Any clue would be really great help in this scenario.
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: Remove multiline comments

Post by Radu »

Hi,

For example in Oxygen's Find/replace dialog you can enable the regular expression support and then search for:

Code: Select all

/\*([\s\S]*?)\*\/
and replace with nothing.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
msambasiva
Posts: 87
Joined: Tue Jul 17, 2018 6:57 am

Re: Remove multiline comments

Post by msambasiva »

Thanks Radu!
I am looking for a way to update the content in the (XSLT) transformation process. My input is xml and output is a html. So I need to exclude the commented code from xml and present the rest of code into html.

How to apply the Regex on the set of node values (sql-statement) and then iterate through the resulted content and display to html? If the comments are in a single line, I can apply regex using for-each. But starting of comments symobol(/*) is one line and ending symbol (*/) on different line.

I need a way to apply the regex set of node values and then iterate through each node to display each line at a time.
msambasiva
Posts: 87
Joined: Tue Jul 17, 2018 6:57 am

Re: Remove multiline comments

Post by msambasiva »

Thanks Radu!

Can you suggest a way to apply Regex on set of nodes at a time as the comments are spread across multiple lines?
Ex:
Comment starting at line <sql-statement>/* Commented for bug#22652320</sql-statement>
and ending at another line <sql-statement> AP_LOOKUP_CODES ALC */ </sql-statement>

Also I want to have the results into an array like structure after regex apply. As I need to iterate through the list and manipulate the each line content before display to output in transformation process.
Any clue would be great help.

Regards,
Samba.
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: Remove multiline comments

Post by Radu »

Hi Samba,

The regular expression example I gave you matches content multi line.
About using an array like structure, you probably need to use a programming language like Java, apply the regexp in the Java code and keep the results in an array for further processing. Maybe you can ask around on Stack Overflow if you do not know how to do this using a programming language.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
msambasiva
Posts: 87
Joined: Tue Jul 17, 2018 6:57 am

Re: Remove multiline comments

Post by msambasiva »

Hi Radu,

The requirement is, Remove commented code (single line/Multi line ) and display the rest of content into table column each sql-statement content into one cell.

Can't we achieve this using XSLT 2.0 alone?

Thanks,
Samba.
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: Remove multiline comments

Post by Radu »

Hi,

Quoting from one of my previous replies:
Also you should first check if your XML document is wellformed. On the Oxygen toolbar there is a "Validate" drop-down button which has a "Check Well-Formedness" action. If the action reports problems, then you will not be able to apply XSLT over the XML document.
So if the XML document is opened in Oxygen, you use the "Check Well-Formedness" action and the document is valid, then you can apply XSLT over it. The XSLT could maybe remove those areas and maybe produce HTML as output. But you will need to create that custom XSLT stylesheet yourself.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply