Share via


Creating XSLT for the Delete operation

To remove an existing document, use XSLT to transform the document into an eConnect XML input document. To create the XSLT for a Delete 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 XSLT File and click Open. Visual Studio creates a file.

    Remove the existing xsl:template node.

  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:xsd="http://www.w3.org/2001/XMLSchema"

    • 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 LeadDelete.xslt file.

    <xsl:stylesheet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    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 an xsl:template node to the stylesheet. Use the match attribute of the template node to specify the nodes in the document to transform.

    The following code sample shows the template used with a lead. Notice how the match attribute specifies to apply the template beginning at the document root.

    <xsl:template match = "/">
    
    

</xsl:template>

  1. Add the document nodes.

    Add XML to the template that reflects the nodes of the eConnect XML document.

    The following example shows the XML that eConnect requires to delete a lead. Notice the following:

    • The XML identifies this as an eConnect document.

    • The document contains the SampleDeleteLead node that the eConnect XML document schema requires.

    • The sampleLeadDelete node specifies the name of the eConnect SQL stored procedure.

    • The LeadID node specifies the name of the input parameter of the sampleLeadDelete business object.

    <eConnect xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <SampleDeleteLead>
        <sampleLeadDelete>
            <LeadID>
            </LeadID>
        </sampleLeadDelete>
    </SampleDeleteLead>
    

</eConnect>

  1. Add values to the document nodes.

    To complete the XSLT transform, populate each node with a value from the service framework XML document.

    The Dynamics GP Service framework produces a serialized version of your document. Your XSLT needs to copy the values from the nodes in your document to the nodes of the eConnect XML document.

    The following example shows XSLT to delete a lead. Notice the use of the <xsl:value-of /> node to specify the value of the LeadID node. The select= attribute specifies the location of the Id value in the source document.

    <eConnect xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <SampleDeleteLead>
        <sampleLeadDelete>
            <LeadID>
                <xsl:value-of select="Lead/Key/Id"/>
            </LeadID>
        </sampleLeadDelete>
    </SampleDeleteLead>
    

</eConnect>

  1. Implement policy for specified nodes (if required).

    If you have implemented a policy for the Delete operation, use the policy information that the framework adds to the document to identify the behaviors that apply to a node or set of nodes. Add XSLT that implements each behavior option of each behavior.

    If you have not implemented a policy for the Delete operation, no additional action is required.

  2. 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.