Share via


Creating XSLT for the GetList operation

To retrieve a collection of summary documents, create XSLT that transforms each eConnect Transaction Requester document into the summary document that the service framework uses. To create the XSLT for the GetList operation, complete the following steps:

  1. Create the XSLT file.

    Start Visual Studio. In the File menu, point to New, and then click File. In the New File window, select General from the list of Categories. Select XSLT File from the Templates, and then click Open. Visual Studio creates an XSLT file.

    If the file contains an <xsl:template /> example node, delete that node from the file.

  2. Add required namespaces.

    Add the following namespaces as attributes to the xsl:stylesheet node:

    • xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    • xmlns:ms ="urn:schemas-microsoft-com:xslt"

    • xmlns:gpxslt="uri://GreatPlainsTransformLibrary"

    • xmlns:gputil="urn:Microsoft.Dynamics.GP.TransformUtilities"

    • xmlns:mbs="https://schemas.microsoft.com/dynamics/2006/01"

    The following code sample shows the xsl:stylesheet node from the LeadGetList.xslt file.

    <xsl:stylesheet
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ms ="urn:schemas-microsoft-com:xslt"
    xmlns:gpxslt="uri://GreatPlainsTransformLibrary"
    xmlns:gputil="urn:Microsoft.Dynamics.GP.TransformUtilities"
    xmlns:mbs="https://schemas.microsoft.com/dynamics/2006/01"
    

version="1.0">

  1. Import required libraries.

    Add an xsl:import node for the Microsoft.Dynamics.GP.StandardLibrary. The file is in the service "XSLT" folder, typically found in the following location:

    C:\Program Files\Microsoft Dynamics\GPWebServices\XSLT

    Notice how the following XSLT sample uses an xsl:import node to add the library. Also notice that the import does not include the file path for the .xslt file. The XSLT file being created must be located in the same folder as the StandardLibrary.xslt file.

    <xsl:import href="Microsoft.Dynamics.GP.StandardLibrary.xslt"/>
    
  1. Specify the templates.

    Add xsl:template nodes to the stylesheet. Use the first template to identify the root node of the XML document. Add XML to the template that identifies this document as a collection of summary documents.

    Also add a xsl:apply-templates node to apply the remaining templates to the XML documents. Use the select attribute to specify the type of nodes to transform.

    The following example shows how to add an XSLT template for a list of lead summary objects. Notice how the XML uses the name of the list class (ArrayOfLeadSummary) created in the lead document assembly.

    <xsl:template match ="/">
    <ArrayOfLeadSummary xmlns:xsi=
        "http://www.w3.org/2001/XMLSchema-instance"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsl:apply-templates select="root//eConnect//Lead"/>
    </ArrayOfLeadSummary>
    

</xsl:template>

Next, add an xsl:templates node that specifies the type of document.

The following example shows the template used for a Lead summary document.

<pre class="checklistscript" IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml">&lt;xsl:template match ="Lead"&gt;

</xsl:template>

  1. Define variables.

    Add variables to the template that supply default values for nodes in the document.

    The following sample shows how to create variables named "isocode" and "decimaldigits. The value of each variable is retrieved from the StandardLibrary.

    <xsl:variable name="isocode">
    <xsl:value-of select="gputil:LocalCurrency(
        /root/mbs:Context/mbs:OrganizationKey/mbs:Id)"/>
    

</xsl:variable> <xsl:variable name="decimaldigits" select="gputil:CurrencyDecimalDigits($isocode)" />

  1. Add the document nodes.

    Add XML to the template that represent the nodes of the summary document returned from the service.

    The following example shows the XML nodes for a lead summary. Notice how the XML specifies the Id property of the Key object.

    <LeadSummary>
    <Key>
        <Id>
        </Id>
    </Key>
    <Name>
    </Name>
    <SalespersonID>
    </SalespersonID>
    <LeadBusinessCategory>
    </LeadBusinessCategory>
    <QualifiedLead>
    </QualifiedLead>
    <LeadSource>
    </LeadSource>
    <ModifiedDate>
    </ModifiedDate>
    

</LeadSummary>

  1. Add values to the document nodes.

    To complete the XSLT transform, populate each node with a value from the eConnect Transaction Requester XML document.

    When the eConnect Transaction Requester retrieves a document, it creates an XML document with nodes that contain values from the Dynamics GP source table. The Transaction Requester uses the column name from the table as the name of the node. Your XSLT needs to copy values from the eConnect nodes into your business document nodes.

    The following example shows XSLT to retrieve a lead summary. Notice the use of the following XSLT nodes:

    • The <xsl:value-of /> node to copy the value of the node. The select= attribute specifies the name from the Transaction Requester XML document that maps to the current property.

    • The LeadBusinessCategory node uses <xsl:choose \> to convert the enumeration integer value found in the database to the corresponding LeadBusinessCategory enumeration string value.

    • The QualifiedLead property maps the integer value retrieved from the database to the corresponding boolean value.

    • The <xsl:if /> that ensures the ModifiedDate is a valid date for Dynamics GP.

    <LeadSummary>
    <Key>
        <Id>
            <xsl:value-of select="LeadID"/>
        </Id>
    </Key>
    <Name>
        <xsl:value-of select="LeadName"/>
    </Name>
    <SalespersonID>
        <xsl:value-of select="SLPRSNID"/>
    </SalespersonID>
    <LeadBusinessCategory>
        <xsl:choose>
        <xsl:when test="LeadBusinessCategory=1">RealEstate</xsl:when>
            <xsl:when test="LeadBusinessCategory=2">Wholesale</xsl:when>
            <xsl:when test="LeadBusinessCategory=3">Retail</xsl:when>
            <xsl:when test="LeadBusinessCategory=4">Contractor</xsl:when>
            <xsl:when test="LeadBusinessCategory=5">Educational</xsl:when>
            <xsl:when test="LeadBusinessCategory=6">Media</xsl:when>
            <xsl:when test="LeadBusinessCategory=7">Software</xsl:when>
            <xsl:when test="LeadBusinessCategory=8">Restaurant</xsl:when>
        </xsl:choose>
    </LeadBusinessCategory>
    <QualifiedLead>
        <xsl:choose>
            <xsl:when test="QualifiedLead=1">0</xsl:when>
            <xsl:when test="QualifiedLead=2">1</xsl:when>
        </xsl:choose>
    </QualifiedLead>
    <LeadSource>
        <xsl:value-of select="LeadSource"/>
    </LeadSource>
    <xsl:if test="gputil:IsNotGreatPlainsDefaultDate(DEX_ROW_TS)">
        <ModifiedDate>
            <xsl:value-of select="DEX_ROW_TS"/>
        </ModifiedDate>
    </xsl:if>
    

</LeadSummary>

  1. Save the file.

    In the File menu, choose Save As. In the Save File As window, enter a filename that complies with Dynamics GP Service XSLT naming requirements. Review the Save in folder, and then click Save.