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

Try something like this:

Code:
<xsl:template match="asset/query">
<query>
  <xsl:variable name="merged" 
      select="string-join(query/sql-statement!replace('--.*$', ''), '#xa;')"/>
  </xsl:variable>
  <xsl:variable name="stripped"
     select="replace($merged, '/\*[.*?]\*/', '', 'm')"/>
  <xsl:for-each select="tokenize($stripped, '#xa;')">
    <query><sql-statement>{.}</sql-statement></query>
  </xsl:for-each>
</query>
</xsl:template>
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
http://www.saxonica.com/
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