Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Preserving space between elements in xslt

pl_sequelJun 27 2012 — edited Jun 28 2012
Running on 11gR1...

Trying to run an xslt to output html... and the transformation strips out the space between my 2 elements...(space between John and Smith is removed)
SELECT XMLSERIALIZE (
          CONTENT XMLTRANSFORM (
                     xmltype (
                        '<data><column name = "USER_FNAME">John</column><column name = "USER_LNAME">Smith</column></data>'),
                     xmltype (
                        '<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body>
<p>
Hello <xsl:value-of select="/data/column[@name=''USER_FNAME'']"/> <xsl:value-of select="/data/column[@name=''USER_LNAME'']"/></p>
</body></html>
</xsl:template>
</xsl:stylesheet>')) AS CLOB)
  FROM DUAL;
Outputs:
<html><body><p>
Hello JohnSmith</p></body></html>
From what I have read, this is the standard behaviour... the only thing I could do to get this to work was to add an xsl:text with xml:space="preserve"
SELECT XMLSERIALIZE (
          CONTENT XMLTRANSFORM (
                     xmltype (
                        '<data><column name = "USER_FNAME">John</column><column name = "USER_LNAME">Smith</column></data>'),
                     xmltype (
                        '<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body>
<p>
Hello <xsl:value-of select="/data/column[@name=''USER_FNAME'']"/><xsl:text xml:space="preserve"> </xsl:text><xsl:value-of select="/data/column[@name=''USER_LNAME'']"/></p>
</body></html>
</xsl:template>
</xsl:stylesheet>')) AS CLOB)
  FROM DUAL;
Part of the issue is I'm also generating the xslt from user-inputted template... user enters simple templating code, I run it through various regexes to generate an xslt.. then run the xslt on xml data.

Example:
<p>Hello {{USER_FNAME}} {{USER_LNAME}}</p>
That snippet is entered by a user, and turned into the xslt listed above... It seems having to replace all whitespace with empty xsl:text elements a bit problematic...Wondering if there is a more elegant solution?

Thanks for the help and advice!
This post has been answered by odie_63 on Jun 28 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 26 2012
Added on Jun 27 2012
4 comments
2,554 views