saravanan s
saravanan s

Reputation: 185

MarkLogic transformation got issue while transform

I am using XSLT in marklogic for transform XML to HTML.

this is my xslt:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="ISO-8859-1" indent="no"/>
    <xsl:template match="/">
        <html>
        <head>
            <title>title</title>
        </head>
        <body>
        <xsl:apply-templates />     
        </body>
    </xsl:template>

    <xsl:template match="ph">
        <xsl:text disable-output-escaping="yes">&lt;/p&gt;</xsl:text>
        <!-- converting inline ph to display para-->
        <p><xsl:apply-templates /></p>
        <xsl:text disable-output-escaping="yes">&lt;p class="para-continued"&gt;</xsl:text>
    </xsl:template>
</xsl:stylesheet>

my sample xml:

<doc>
<p>some text bla blasome text bla blasome text bla blasome text bla bla</p>
<p>some text bla blasome text <ph>ph content</ph> bla blasome text bla blasome text bla bla</p>
</doc>

Tags are showing in the image

The tags are displaying in HTML when using <xsl:text> in MarkLogic, Oxygen does not make any issue, please refer the attached image.

Upvotes: 0

Views: 159

Answers (2)

grtjn
grtjn

Reputation: 20414

I would recommend using xsl:for-each-group, that allows for a more flexible and robust solution:

let $xml := document {
  <doc>
    <p>1some text bla blasome text bla blasome text bla blasome text bla bla</p>
    <p>2some text bla blasome text <ph>ph content</ph> 3bla blasome text bla blasome text bla bla</p>
  </doc>
}

let $xsl :=
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="html" encoding="ISO-8859-1" indent="no"/>

    <xsl:template match="/doc">
      <html>
        <head>
          <title>title</title>
        </head>
        <body>
          <xsl:apply-templates />
        </body>
      </html>
    </xsl:template>

    <xsl:template match="node()|@*">
      <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
    </xsl:template>

    <xsl:template match="*[ph]">
      <xsl:variable name="parent" select="."/>

      <xsl:for-each-group select="node()" group-starting-with="node()[self::ph | preceding-sibling::node()[1][self::ph]]">
        <xsl:element name="{{node-name($parent)}}">
          <xsl:copy-of select="$parent/@*"/>
          <xsl:apply-templates select="current-group()"/>
        </xsl:element>
      </xsl:for-each-group>
    </xsl:template>
  </xsl:stylesheet>

return xdmp:xslt-eval($xsl, $xml)

HTH!

Upvotes: 1

mblakele
mblakele

Reputation: 7842

Check in ErrorLog.txt and you should see something like this:

XSLT-DISOUTPUTESC (err:XTRE1620) Disable output escaping not supported: /*:stylesheet/*:template[2]/*:text[1]

In other words, the current release of MarkLogic doesn't implement that feature. It's optional: http://www.w3.org/TR/xslt20/#d-o-e-in-data-model

You could try something like this. Note that I've doubled up the curly braces to escape them in XQuery. This might also be a good place to use xsl:for-each-group.

xdmp:xslt-eval(
  <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="ISO-8859-1" indent="no"/>
    <xsl:template match="/">
        <html>
        <head>
            <title>title</title>
        </head>
        <body>
        <xsl:apply-templates />
        </body>
        </html>
    </xsl:template>


    <xsl:template match="*[ph]">
      <xsl:variable name="qname" select="node-name(.)"/>
      <xsl:element name="{{ $qname }}">
        <xsl:apply-templates select="ph[1]/preceding-sibling::node()"/>
      </xsl:element>
      <xsl:element name="{{ $qname }}">
        <xsl:apply-templates select="ph[1]/node()"/>
      </xsl:element>
      <xsl:element name="{{ $qname }}">
        <xsl:attribute name="class">para-continued</xsl:attribute>
        <xsl:apply-templates select="ph[1]/following-sibling::node()"/>
      </xsl:element>
    </xsl:template>

    <xsl:template match="*">
      <xsl:element name="{{ node-name(.) }}">
        <xsl:apply-templates select="node()"/>
      </xsl:element>
    </xsl:template>
  </xsl:stylesheet>,
  <doc>
    <p>some text bla blasome text bla blasome text bla blasome text bla bla</p>
    <p>some text bla blasome text
      <ph>ph content</ph>
      bla blasome text bla blasome text bla bla
    </p>
  </doc>)

Using 7.0-4.3:

<doc>
  <p>some text bla blasome text bla blasome text bla blasome text bla bla</p>
  <p>some text bla blasome text</p>
  <p>ph content</p>
  <p class="para-continued">
      bla blasome text bla blasome text bla bla
  </p>
</doc>

Upvotes: 1

Related Questions