Advanced Customization > Info*Engine User’s Guide > Display Webject Reference > Display Webjects for HTML > Apply-XSL
  
Apply-XSL
DESCRIPTION
Applies an XSL stylesheet to an Info*Engine group of objects to generate a textual representation of the group. The generated output is determined by the contents of the XSL stylesheet.
SYNTAX
<ie:webject name="Apply-XSL" type="DSP">
  <ie:param name="CONTENT_TYPE" data="mimetype"/>
  <ie:param name="DBUSER" data="username"/>
  <ie:param name="GROUP_IN" data="group_name"/>
  <ie:param name="PASSWD" data="password"/>
  <ie:param name="XSL_PARAM" data="name_value_pair"/>
  <ie:param name="XSL_URL" data="url_location"/>
</ie:webject>
PARAMETERS
Required
Select
Optional
XSL_URL
CONTENT_TYPE
DBUSER
GROUP_IN
PASSWD
XSL_PARAM
CONTENT_TYPE
Specifies the MIME content type to be associated with the result being displayed. Using html text as the content type returns an HTML-formatted document to the calling application or web browser.
The default for this parameter is text/html, which produces an XML-formatted document. This parameter is optional.
DBUSER
Specifies the username to be used to authenticate to XSL_URL. If the XSL templates to be used by the webject reside on a remote HTTP server, then this parameter should be used in conjunction with the PASSWD attribute.
This parameter is optional.
GROUP_IN
Identifies the name of the group to be used as the input source. The group can be a VDB group or a Context group. For further information about groups, see Info*Engine Data Management.
The default for this parameter is to use the last group defined in the VDB. This parameter is optional.
PASSWD
Specifies the password corresponding to DBUSER.
This parameter is optional.
XSL_PARAM
Defines XSL parameters that are then passed to the XSL stylesheet named in the XSL_URL parameter. You enter the value for the XSL_PARAM parameter in the form XSL_name=XSL_value where XSL_name is the name of a parameter in the XSL stylesheet and XSL_value is the value you want set for the parameter.
The default for XSL_PARAM is that no parameters are passed to the stylesheet. Multiple values can be specified for this parameter. This parameter is optional.
XSL_URL
Identifies the location of an XSL stylesheet to apply to the default output group. A relative URL or a fully qualified URL can be specified. Relative URLs are relative to the Info*Engine server task template root.
Fully qualified URLs are dereferenced using Auth-Map context group data. The Auth-Map context group is searched for a username and password based on the domain name found in the fully qualified URL. For example, assume that the fully qualified URL is:
http://machine.com/Windchill/infoengine/servlet/IE/tasks/ com/company/createGroupData.xsl
The Auth-Map context group is searched for a username and password with http://machine.com as an INSTANCE name. If a username and password are found, BASIC authentication information is used when accessing the URL. If no username and password is found, no authentication information is sent to the remote web server.
If the data value contains the string :// it is assumed to be a fully qualified Internet URL. If the data value does not contain the string, it is assumed to be a local file relative to the current task root directory.
This parameter is required.
Browser Example
Example webject
The following Apply-XSL webject formats the output from a task, then displays the output in a browser:
<ie:webject name="Apply-XSL" type="DSP">
  <ie:param name="CONTENT_TYPE" data="text/html"/>
  <ie:param name="XSL_URL"
               data="com/company/ApplyXsl.xsl"/>
</ie:webject>
XSL stylesheet
The following XSL stylesheet is applied to an input group with a CLASS of “EmployeeData” with each element containing attributes NAME and ADDRESS attributes:
<?xml version='1.0'?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
    xmlns:wc="http://www.ptc.com/infoengine/1.0">
<xsl:template match="/wc:COLLECTION/EmployeeData">
<html>
<head><title>Apply-XSL Example</title></head>
<body>
<table>
<tr>
  <th>name</th><th>Home Address</th>
</tr>
<xsl:for-each select="wc:INSTANCE">
  <tr>
    <td><xsl:value-of select="NAME"/></td>
    <td><xsl:value-of select="ADDRESS"/></td>
  </tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Browser display
The output is generated using HTML by specifying the CONTENT_TYPE as text/html. The resulting web browser display consists of the following table of names and addresses:
Excel Example
Example JSP Page
The following JSP page contains the Apply-XSL webject. The webject defines XSL parameters, then uses a stylesheet to format the output from a task for display in Excel:
<%@page language="java" session="false" errorPage="../IEError.jsp"
contentType="application/ms-excel"%>
<%@ taglib uri="http://www.ptc.com/infoengine/taglib/core"
prefix="ie"%>

<%
/*********************************************
*
* DESCRIPTION
* Build html table for import Microsoft Word, Excel, Powerpoint 2000.
*
*********************************************/
// execute create group task to get group info
%>

<ie:task uri="com/company/CreateGroup.xml"/>

<%
// call Apply-XSL Webject to translate data into excel data
%>

<ie:webject name="Apply-XSL" type="DSP">
  <ie:param name="XSL_URL" data="com/company/ExcelWorkbook.xsl"/>
  <ie:param name="XSL_PARAM" data="CLASS='EmployeeData'"/>
  <ie:param name="XSL_PARAM"
            data="HEADERS='NAME=Employee,ADDRESS=Home Address,'"/>
  <ie:param name="XSL_PARAM" data="USE-COLUMNS='NAME,ADDRESS,EMAIL'"/>
</ie:webject>
XSL stylesheet
In the example JSP page, the following XSL parameters are passed to the XSL stylesheet:
CLASS='EmployeeData'
HEADERS='NAME=Employee,ADDRESS=Home Address,'
USE-COLUMNS='NAME,ADDRESS,EMAIL'
The parameters change the class, columns used, and headers defined in the stylesheet so that the stylesheet can manipulate and format the data.
The Apply-XSL webject on the JSP page calls the following XSL stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  xmlns:wc="http://www.ptc.com/infoengine/1.0">

<xsl:output omit-xml-declaration="yes"/>

<xsl:param name="CLASS">EMP</xsl:param>
<xsl:param name="USE-COLUMNS">EMPNO,ENAME,POS,</xsl:param>
<xsl:param name="HEADERS">EMPNO=E,ENAME=N,POS=P,</xsl:param>

<xsl:template match="/wc:COLLECTION">
  <table border='0' cellpadding='0' cellspacing='0' width='627'
         style='border-collapse:collapse;table-layout:fixed;width:350pt'>
    <col width='200'
         style='mso-width-source:userset;mso-width-alt:5400;width:100pt'/>
    <col width='200'
         style='mso-width-source:userset;mso-width-alt:5400;width:100pt'/>
    <col width='200'
         style='mso-width-source:userset;mso-width-alt:6700;width:175pt'/>

    <xsl:for-each select="//*[name()=$CLASS]">
      <tr height='17' style='height:12.75pt'>
        <xsl:call-template name="table-headers"/>
      </tr>
      <xsl:for-each select="wc:INSTANCE">
      <tr>
          <xsl:for-each select="*">
            <xsl:call-template name="html-table-value"/>
          </xsl:for-each>
      </tr>
      </xsl:for-each>
    </xsl:for-each>
  </table>

</xsl:template>

<xsl:template name="html-table-value">
  <xsl:variable name="TARGET" select="name()"/>
  <xsl:if test="contains( $USE-COLUMNS, name() )">
    <td height='68' class='xl27' style='height:20.0pt'>
      <xsl:value-of select="."/>
    </td>
  </xsl:if>
</xsl:template>

<xsl:template name="table-headers">
  <xsl:for-each select="child::wc:INSTANCE[position()=1]/child::*">
    <xsl:variable name="EQUALS" select="'='"/>
    <xsl:variable name="DELIM" select="','"/>
    <xsl:if test="contains( $USE-COLUMNS, name() )">

      <xsl:message>
        <xsl:text> Column Header </xsl:text>
        <xsl:value-of select="$HEADERS"/>
        <xsl:text> Name </xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>

    <td height='17' class='xl24' width='100' style='height:25.75pt
;width:100pt'>
        <xsl:if test="contains( $HEADERS, name() )">
          <xsl:variable name="TEMP"
                              select="substring-after( $HEADERS, name
() )"/>
          <xsl:variable name="TEMP1"
                              select="substring-after( $TEMP, $EQUALS
)"/>
          <xsl:variable name="VALUE" select="substring-before(
$TEMP1, $DELIM)"/>
          <xsl:value-of select="$VALUE"/>
        </xsl:if>
        <xsl:if test="not(contains( $HEADERS, name() ))">
          <xsl:value-of select="name()"/>
        </xsl:if>
      </td>

    </xsl:if>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
MS Excel display
To display the output directly in MS Excel, execute the URL for the page from the Excel Open dialog. For example, if the ExcelWorkbook.jsp page were saved to <Windchill>/codebase/com/company/ExcelWorkbook.jsp you might enter the following URL::
http://host/Windchill/com/company/ExcelWorkbook.jsp
The following picture displays the resulting Excel columns. Notice that only two of the three headers were supplied. The EMAIL header comes from the column name.