cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT does not honor the output element

iyerha
Deputy Chef I
Deputy Chef I

Hi,

I am using XML tools by workato and the Transform using XSLT action.

I am converting an XML input to a text output. I do this using the following XSLT element:

<xsl:output method="text" encoding="UTF-8"/>

But workato always seems to add the XML prolog to the output i.e. I get <?xml version="1.0" encoding="UTF-8"?> prefixed to the output.

This works correctly when I use another XSLT testing tool. Is this a bug? Is there a workaround?

Thanks,

Hari

5 REPLIES 5

Prudvi
Executive Chef II
Executive Chef II

Hi @iyerha,
Did you try adding the following attribute to the xml:output omit-xml-declaration="yes".
"<xsl:output method="text" omit-xml-declaration="yes" encoding="UTF-8"/>"
Regards,
Prudvi

 

iyerha
Deputy Chef I
Deputy Chef I

Hi Prudvi,

I tried that and it still emits the XML prolog. It appears to be a bug.

Thanks,

shivakumara
Executive Chef III
Executive Chef III

Hi @iyerha ,
I hope you are doing well,
Here is my understanding on the problem statement:
1. You are basically converting given XML to Text (RAW output) applying XSLT transformation.
2. However, you are getting a response which is including XML header to it (i.e. <?xml version="1.0" encoding="UTF-8"?>)

Here I am adding my insights to the problem statement, let me know if that works for you
1. Please kindly check your XSLT content whether it is applied to your XML.

Here I am adding my input XML, Provided XSLT contents and output.

Input XML
-------------------------
<?xml version="1.0" encoding="UTF-8"?>
<students>
  <student>
    <name>John Doe</name>
    <grade>A</grade>
  </student>
  <student>
    <name>Jane Smith</name>
    <grade>B+</grade>
  </student>
</students>

XSLT applied:
---------------
<xsl:output method="text" encoding="UTF-8"/>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <xsl:output method="html" indent="yes"/>

  <xsl:template match="/">
    <html>
      <head>
        <title>Student Grades</title>
      </head>
      <body>
        <h2>Student Grade Report</h2>
        <table border="1">
          <tr>
            <th>Name</th>
            <th>Grade</th>
          </tr>
          <xsl:for-each select="students/student">
            <tr>
              <td><xsl:value-of select="name"/></td>
              <td><xsl:value-of select="grade"/></td>
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

Output:
----------------
{
  Output: <html>
<head><title>Student Grades</title></head>
<body>
<h2>Student Grade Report</h2>
<table border="1">
<tr>
<th>Name</th>
<th>Grade</th>
</tr>
<tr>
<td>John Doe</td>
<td>A</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>B+</td>
</tr>
</table>
</body>
</html>
}

Please let me know if the provided output is what you were expecting.

Thanks and Regards,
Shivakumara K A



Hi Shivakumara,

When output is set to html, there is no XML prolog as you have demonstrated. But I am trying to convert to plain text and when I set the output to text, I still get the prolog. Here is my recipe test result:

{
  Response content type: rawdatatxt,
  Document: <books>
    <book>
        <title>Effective Java</title>
        <author>Joshua Bloch</author>
        <year>2018</year>
    </book>
    <book>
        <title>Clean Code</title>
        <author>Robert C. Martin</author>
        <year>2008</year>
    </book>
</books>,
  XSLT: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" omit-xml-declaration="yes" encoding="UTF-8"/>

    <xsl:template match="/books">
        <xsl:apply-templates select="book"/>
    </xsl:template>

    <xsl:template match="book">
        Title: <xsl:value-of select="title"/><xsl:text>&#10;</xsl:text>
        Author: <xsl:value-of select="author"/><xsl:text>&#10;</xsl:text>
        Year: <xsl:value-of select="year"/><xsl:text>&#10;&#10;</xsl:text>
    </xsl:template>
</xsl:stylesheet>
}
{
  Output: <?xml version="1.0" encoding="UTF-8"?>

        Title: Effective Java

        Author: Joshua Bloch

        Year: 2018


        Title: Clean Code

        Author: Robert C. Martin

        Year: 2008

}

However, I agree that using html is a workaround to the problem. But it's odd to use html when the output is not html.