Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Matt Taylor 873 posts 2086 karma points
    Mar 14, 2012 @ 15:16
    Matt Taylor
    0

    XSLTHelper.InvokeXSLT - What am I doing wrong?

    I have some code to run through a list of order lines and send emails using the following XSLT file:

    <xsl:param name="orderLine" />

      <xsl:template match="/">

        <h2>
          Your subscription renewal date is approaching. <xsl:value-of select="$orderLine/@id"/>
        </h2>   
        <table cellspacing="0" cellpadding="0" border="0" width="50%" style="margin-top: 15px;">
          <tr>
            <td>
              Subscription
            </td>
            <td>
              Username
            </td>
            <td>
              Activation Key
            </td>
            <td>
              Expiry Date
            </td>
          </tr>
          <tr>
            <td>
              <xsl:value-of select="$orderLine/properties/productName"/>
            </td>
            <td>
              <xsl:value-of select="$orderLine/properties/memberUsername"/>
            </td>
            <td>
              <xsl:value-of select="$orderLine/properties/activationKey"/>
            </td>
            <td>
              <xsl:value-of select="$orderLine/properties/expiryDate"/>
            </td>
          </tr>
        </table>

      </xsl:template>

    The following code works fine, using the GetXML method to get the XPathNodeIterator, the bodyText variable is
    populated with the details for each order line:

    XPathNodeIterator orders = TeaCommerce.Library.GetFinalizedOrdersXml().Current.Select("order");
    TeaCommerce.Data.Order order = TeaCommerce.Razor.TeaCommerce.GetOrder(Convert.ToInt32(orders.Current.GetAttribute("id", "")));
    var subscriptions = from ol in order.OrderLines select ol;

    foreach (OrderLine subscriptionOrderLine in subscriptions)
    {
    int orderUmbracoLanguageID = Convert.ToInt32(orders.Current.GetAttribute("umbracoLanguageId", ""));

    XPathNodeIterator orderLines = orders.Current.Select("orderLine");

    while (orderLines.MoveNext())
    {
    Dictionary<string, XPathNodeIterator> parameters = new Dictionary<string, XPathNodeIterator>();
    parameters.Add("orderLine", subscriptionOrderLine.GetXml());
    string bodyText = XSLTHelper.InvokeXSLT("subscription_reminder_email.xslt", null, orderUmbracoLanguageID, parameters, false);

    <code to send email ...>
    }

    This code is a little more efficient as it is not calling GetOrder however it does not work.
    The bodyText variable gets set but is missing the order line property values for all but one order line.

    int orderUmbracoLanguageID = Convert.ToInt32(orders.Current.GetAttribute("umbracoLanguageId", ""));
    XPathNodeIterator orderLines = orders.Current.Select("orderLine");
    while (orderLines.MoveNext())
    {
      Dictionary<string, XPathNodeIterator> parameters = new Dictionary<string, XPathNodeIterator>();
      parameters.Add("orderLine", orderLines);
      string bodyText = XSLTHelper.InvokeXSLT("subscription_reminder_email.xslt", null, orderUmbracoLanguageID, parameters, false);

    <code to send email ...>
    }

    It's weird to me...what am I doing wrong? Is there a bug in XSLTHelper.InvokeXSLT?

    Regards,

    Matt

     

  • Rune Grønkjær 1372 posts 3103 karma points
    Mar 14, 2012 @ 15:33
    Rune Grønkjær
    0

    Hi Matt,

    Have you tried <xsl:copy-of select="$orderLine" /> to see what is being added to that parameter?

    How is it failing?

    /Rune

  • Matt Taylor 873 posts 2086 karma points
    Mar 14, 2012 @ 15:46
    Matt Taylor
    0

    Good idea Rune,

    There's only one order with two orderlines.

    The value of <xsl:copy-of select="$orderLine" /> is empty for the 2nd orderline works for the first.

    Not sure why though.

  • Rune Grønkjær 1372 posts 3103 karma points
    Mar 14, 2012 @ 16:46
    Rune Grønkjær
    0

    Pretty weird stuff.

    If it was me I would run it locally and debug the code. You will be able to see if two orderlines is returned from you select, or if some mad pixie is tampering with your code!

    /Rune

Please Sign in or register to post replies

Write your reply to:

Draft