View Single Post
  #4 (permalink)  
Old September 5th, 2019, 05:56 AM
mhkay's Avatar
mhkay mhkay is offline
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

Try something like this:

<xsl:template match="asset/query">
  <xsl:variable name="merged" 
      select="string-join(query/sql-statement!replace('--.*$', ''), '#xa;')"/>
  <xsl:variable name="stripped"
     select="replace($merged, '/\*[.*?]\*/', '', 'm')"/>
  <xsl:for-each select="tokenize($stripped, '#xa;')">
Before #xa; insert ampersand (I had formatting problems with ampersands).

The idea is that the first variable $merged first removes single-line comments from each sql-statement using a replace() call, then joins all the lines with a newline character as separator; then the next variable $stripped removes multiline comments with another replace() call; then the tokenize() splits the resulting string on newline boundaries and for each line it regenerates a nested query/sql-statement element. The use of {.} assumes that expand-text="yes" is specified at xsl:stylesheet level.
Michael Kay
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference

Last edited by mhkay; September 5th, 2019 at 06:08 AM..
Reply With Quote