Support XSLT 2.0 in Templates

Comments

9 comments

  • Official comment
    Gerald

    Hey Jason,

    Thanks for visiting our support forums. I am excited to see the teamwork in seeing if we can get your desired results within ShipWorks. We really appreciate Nathan's assistance on updating this template to meet your needs.

    I can definitely see the benefit in having XSLT 2.0 available for not only situations similar to this, but a variety of other tips and tricks. 

    Using the information attached to this profile, I have created a support ticket to further discuss your request.

    Again, thank you Nathan for your assistance, and I look forward to speaking with you further Jason

     

    Gerald C

    Comment actions Permalink
  • Nathan H.

    Give an example of what you are trying to do.

    0
    Comment actions Permalink
  • Jason Body

    Given a list of 2,500 skus, see if one of them matches a sku that was ordered in this order, and then if the order is going to California add HTML Text to UI to tell shipper to add the appropriate PROP 65 decal.

    Any good way to do this in a template without 1,000 if statements?   If you supported XSLT 2.0 "Matches" I could do in one line.

    0
    Comment actions Permalink
  • Jason Body

    Here is the if case that works with current Templates if had one sku I need to check, but i need to check 2,500 different products to see if they need the Prop Warning which currently I can only do with your filters "Matches Regex" feature.

    <xsl:if test="contains(SKU,'XXX10719')">
    <tr style="background-color=red">
    <td colspan="4" style="font-size=20" align="left">
    Add DEHP Sticker to product
    </td>
    </tr>
    </xsl:if>

    0
    Comment actions Permalink
  • Nathan H.

    is the list of 2,500 skus in a table in the sql server?

    0
    Comment actions Permalink
  • Jason Body

    No but i can put it there if needed.   Currently just a | delimited string.

    0
    Comment actions Permalink
  • Nathan H.

    Here is what I would do.

    I would create a very simple table in the SQL Server with 2 columns "Sku" and "PROP65".

    Datatype for Sku should be NVARCAR(50) or MAX if needed.

    Datatype for PROP65 should be bit but to keep thing simple we can use int.

    You should insert the data appropriately ie; SKU: XXX10719 has a PROP65 value of 1 where as XXX10718 has a value of 0.

     

    Then we get to your template solution, we can use C# within the XSL 1.0 processor to run Queries on the database that is outside the scope of the XML document.

    Here is a non tested example.

     

    <!DOCTYPE xsl:stylesheet[ <!ENTITY nl "&#xd;&#xa;"> ]>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sw="http://www.interapptive.com/shipworks" extension-element-prefixes="sw" xmlns:user="urn:my-scripts" xmlns:msxsl="urn:schemas-microsoft-com:xslt">

    <xsl:import href="System\Snippets" />
    <msxsl:script language="CSharp" implements-prefix="user">
    <msxsl:assembly name="System.Data"/>
    <msxsl:assembly name="System.Windows.Forms"/>
    <msxsl:using namespace="System"/>
    <msxsl:using namespace="System.Data"/>
    <msxsl:using namespace="System.Data.SqlClient"/>
    <msxsl:using namespace="System.Windows.Forms"/>
    <msxsl:using namespace="System.Net"/>
    <msxsl:using namespace="System.Net.Cache"/>
    <msxsl:using namespace="System.IO"/>
    <![CDATA[
    public string GetMain (string KSku)
    {
    string strResult = "";
    string sql = "SELECT [PROP65] FROM [YOURTABLENAME] WHERE [SKU] = '"+ KSku+"'";
    SqlConnection conn = new SqlConnection("Server=YOURSERVERNAME;Database=YOURDATABASENAME;User Id=sa;Password = PASSWORD_FOR_SA_ACCOUNT;WSID=0000100001;MultipleActiveResultSets=true;");
    try
    {
    conn.Open();
    SqlCommand insertCMD = new SqlCommand(sql, conn);
    SqlDataReader reader = insertCMD.ExecuteReader();
    if (reader.HasRows) {
    while (reader.Read()) {
    strResult = strResult + reader["PROP65"].ToString() +" ; ";
    }
    }
    strResult = strResult.Substring(0, strResult.Length- 3);
    }
    catch (Exception e1) {}
    conn.Close();
    return strResult.ToString();
    }
    ]]>
    </msxsl:script>
    <xsl:output method="text" encoding="utf-8" />

    <!-- Start of template -->
    <xsl:template match="/"><xsl:apply-templates /></xsl:template>
    <xsl:template match="ShipWorks">
    <xsl:variable name="Order" select="Customer/Order" />

    <xsl:for-each select="$Order/Item">
    <!--GetMain will output a 0 or 1-->
    <xsl:value-of select="user:GetMain(SKU)" />

    </xsl:for-each>

    </xsl:template>
    </xsl:stylesheet>

     

    0
    Comment actions Permalink
  • Jason Body

    Thank you I will give this a try

    0
    Comment actions Permalink
  • Nathan H.

    No problem. Let me know if you have any trouble with implementation.

    0
    Comment actions Permalink

Please sign in to leave a comment.