cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT mapping

Former Member
0 Kudos

Hi guys,

I was planning to output a HTML document from XSLT mapping. I need a table as output.

My input data goes like this:

<items>

<item>

    <type>Dog</type>

    <name>Fido</name>

</item>

<item>

    <type>Person</type>

    <name>Bob</name>

</item>

<item>

    <type>Plant</type>

    <name>Tomato</name>

</item>

<item>

    <type>Cat</type>

    <name>Garfield</name>

</item>

</items>

I need these details tabulated in an HTML file.

Please let me know what the target data type should be!!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

Try this:

<?xml version="1.0" encoding="UTF-8"?>

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

   <xsl:template match="/">

      <table border="1">

         <tr>

            <th>Type</th>

            <th>Name</th>

         </tr>

         <xsl:for-each select="//item">

            <tr>

               <td>

                  <xsl:value-of select="type"/>

               </td>

               <td>

                  <xsl:value-of select="name"/>

               </td>

            </tr>

         </xsl:for-each>

      </table>

   </xsl:template>

</xsl:stylesheet>

Thanks

Amit Srivastava

Former Member
0 Kudos

Hey Amit!!

I know what the xsl should look like..my doubt is about the target data type. What should it look like?

Former Member
0 Kudos

Hi,

>>my doubt is about the target data type. What should it look like?

U can create dummy receiver structure (DT, MT)...

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi Amit,

You mean a receiver with some xsd type element?

Regards,

Meghana

Former Member
0 Kudos

Hello,

>>You mean a receiver with some xsd type element?

Yes, since u r using XSLT so PI won't validate the xslt output with the receiver structure.

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi Amit,

Thanks. I followed it. I used FILE adapter on the source and target sides. The output file is empty 😐

This is my transformation :

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

    version="1.0">

    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/">

      <xsl:for-each select="ITEMS/ITEM">

        <table border="2">

        <tbody>

            <tr>

              <th><xsl:value-of select="TYPE"/></th>

           

              <th><xsl:value-of select="NAME"/></th>

            </tr>

          </tbody>

                </table>

         

      </xsl:for-each>

    </xsl:template>

</xsl:stylesheet>

Former Member
0 Kudos

Hello,

It should work...Check ur OM output.

BTW, below is the HTML content which i have created using file adapter

Thanks

Amit Srivastava

Former Member
0 Kudos

This is the error message I got when tested in OM:

Unable to display tree view; Error when parsing an XML document (Premature end of file.)

Former Member
0 Kudos

And I dont think we can view the HTML content in OM. Can we?

Regards,

Meghana

Former Member
0 Kudos

Hello,

Use this:

<?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" indent="yes"/>

   <xsl:template match="/">

      <table border="2">

         <xsl:for-each select="//ITEMS/ITEM">

            <tbody>

               <tr>

                  <th>

                     <xsl:value-of select="TYPE"/>

                  </th>

                  <th>

                     <xsl:value-of select="NAME"/>

                  </th>

               </tr>

            </tbody>

         </xsl:for-each>

      </table>

   </xsl:template>

</xsl:stylesheet>

Thanks

Amit Srivastava

iaki_vila
Active Contributor
0 Kudos

Hi Meghana,

If you are using the XSL transformation with the html output it is possible that error because you are not getting a xml. Try to check with the option display as text inside the Operation mapping.

Regards.

Former Member
0 Kudos

Amit,

Thanks a lot. It works fine now. Is it because of writing <tbody> tag inside foreach??

Regards,

Meghana

Former Member
0 Kudos

Hi Iñaki,

Thanks!!

Regards,

Meghana

Former Member
0 Kudos

>>Is it because of writing <tbody> tag inside foreach??

Yes

Thanks

Amit Srivastava

Answers (2)

Answers (2)

peter_wallner2
Active Contributor
0 Kudos

Hello Meghana,

Yes, that would be interesting. Do you need the HTML as an attachment for an email?

Best regards,

Peter

Former Member
0 Kudos

Hi Peter,

Yes, the HTML file is to be mailed as an attachment.

Regards,

Meghana

peter_wallner2
Active Contributor
0 Kudos

Hello Meghana,

An example of one of my scenarios. Make sure you use the XSD "mail_package.xsd" from SAP.

Good luck,

Peter

Former Member
0 Kudos

Hi Peter,

Thank you!

Regards,

Meghana

iaki_vila
Active Contributor
0 Kudos

Hi Meghana,

Go ahead with Amit's example. I have a little curiosity what kind of PI scenario you need a html format, could you share with us why you need this output format?

Regards.

Former Member
0 Kudos

Hi!

As Peter pointed out, I need the data tabulated into an HTML file and sent as an attachment.

Regards,

Meghana