View Single Post
  #1 (permalink)  
Old September 4th, 2019, 03:39 AM
msambasiva@gmail.com msambasiva@gmail.com is offline
Registered User
Points: 44, Level: 1
Points: 44, Level: 1 Points: 44, Level: 1 Points: 44, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2017
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
Default Excluded commented content from an xml

Hi,

XSLT 2.0, Saxon Parser

There are DB query statements in an xml file. Need to exclude the commented content in the generated output.
There are three types of comments
1) Single line comments. I've taken care to remove these comments
2) Multi line comments in a single line. I've taken care to remove these comments
3) Multi line comments spread into a different lines.
Looking for your suggestion to remove these comments.

It would be great help if you can suggest any clue on this.

Thanks in advance,
Samba.

Below is the sample xml content and xsl logic

Code:
<asset>
<query>
	<query>
		<sql-statement>SELECT  RT.TRANSACTION_ID RCV_TRANSACTION_ID               ,</sql-statement>
	</query>
	<query>
		<sql-statement>       --TRUNC(RT.TRANSACTION_DATE) RCV_TRANSACTION_DATE           ,</sql-statement>
	</query>
	<query>
		<sql-statement>       SL.ITEM_ID ITEM_ID                                 ,</sql-statement>
	</query>
	<query>
		<sql-statement>       PL.ITEM_DESCRIPTION ITEM_DESCRIPTION --Comments              ,</sql-statement>
	</query>
	<query>
		<sql-statement>       PL.VENDOR_PRODUCT_NUM SUPPLIER_ITEM                   ,</sql-statement>
	</query>
	<query>
		<sql-statement>       ps.po_header_id PO_HEADER_ID                       ,</sql-statement>
	</query>
	<query>
		<sql-statement>       PH.SEGMENT1 PO_NUMBER                              ,</sql-statement>
	</query>
	<query>
		<sql-statement>       PL.LINE_NUM PO_LINE                                ,</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>       PS.SHIPMENT_NUM PO_SCHEDULE                        ,</sql-statement>
	</query>
	<query>
		<sql-statement>       SH.RECEIPT_NUM RECEIPT_NUMBER                      ,</sql-statement>
	</query>
	<query>
		<sql-statement>       SL.LINE_NUM RECEIPT_LINE                           ,</sql-statement>
	</query>
	<query>
		<sql-statement>       PS.NEED_BY_DATE NEED_BY_DATE                       ,</sql-statement>
	</query>
	<query>
		<sql-statement>        ALC1.lookup_code MATCH_BASIS_LOOKUP_CODE         ,</sql-statement>
	</query>
	<query>
		<sql-statement>        ALC1.displayed_field  MATCH_BASIS ,</sql-statement>
	</query>
	<query>
		<sql-statement>       /* bug#22652320 */ </sql-statement>
	</query>
</query>
</asset>

  <xsl:template match="asset">
		<p><xsl:apply-templates select="sql-statement"/></p>
	</xsl:template>

	<xsl:template match="sql-statement">
		<xsl:choose>
			<!-- Contains single line comment 
			<sql-statement>       --TRUNC(RT.TRANSACTION_DATE) RCV_TRANSACTION_DATE           ,</sql-statement>
			<sql-statement>       PL.ITEM_DESCRIPTION ITEM_DESCRIPTION --Comments              ,</sql-statement>
			-->
			<xsl:when test="contains(.,'--')">
				<xsl:if test="normalize-space(substring-before(.,'--')) ne ''">
					<xsl:value-of select="substring-before(.,'--')"/><BR/>
				</xsl:if>
			</xsl:when>
			<!--	Contains multi line comment in one line
			<sql-statement>       /* bug#22652320 */ </sql-statement>
			--> 
			<xsl:when test="contains(.,'/*') and contains(.,'*/')">
				<xsl:if test="normalize-space(substring-before(.,'/*')) ne '' or normalize-space(substring-after(.,'*/')) ">
					<xsl:value-of select="concat(normalize-space(substring-before(.,'/*')), normalize-space(substring-after(.,'*/')))"/><BR/>
				</xsl:if>
			</xsl:when>
			<!--	Contains multi line comment in different lines
				<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>
			--> 
			
			<xsl:otherwise>
					<xsl:value-of select="."/><BR/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
Reply With Quote