Quantcast
Channel: BizTalk Server General Forum
Viewing all articles
Browse latest Browse all 872

XSLT Dupplicates attribute

$
0
0

Hi,

I'm getting an error when doing a XSLT Mapping in BizTalk 2009.

My XSLT code for the attriubute staff I want in the destination file is:

            <ns0:Attribute>
              <xsl:variable name="var:v30" select="&quot;staff&quot;" />
              <xsl:attribute name="id">
                <xsl:value-of select="$var:v30" />
              </xsl:attribute>
              <xsl:for-each select="../../../../InputMessagePart_3/s0:GetPersonnelObjectResponse/s0:GetPersonnelObjectResult">
                <xsl:variable name="var:v28" select="userCSharp:StringConcat (string(s0:ObjectName),&quot;; &quot;)"/>
                <xsl:value-of select="$var:v28" />
              </xsl:for-each>
            </ns0:Attribute>

You can find the all the xsl code below.

The problem I'm having is that instead of getting <Attribute id="staff"> Staff A; Staff B; Staff C;</Attribute>, my out dublicates and write

<Attribute id="staff"> Staff A; Staff B; Staff C; Staff A; Staff B; Staff C;</Attribute>

Anyone who can help my with this?

//Victor


  <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
  <xsl:template match="/">
    <xsl:apply-templates select="/s1:Root" />
  </xsl:template>
  <xsl:template match="/s1:Root">
    <ns0:Products>
      <xsl:for-each select="InputMessagePart_1/s2:GetEducationObjectResponse/s2:GetEducationObjectResult">
        <xsl:for-each select="s2:EducationObject">
          <xsl:variable name="var:v1" select="userCSharp:StringConcat(string(s2:ObjectName/text()) , &quot; - &quot; , string(../../../../InputMessagePart_0/s2:ObjectPriceName/s2:Description/text()))" />
          <xsl:variable name="var:v2" select="userCSharp:StringConcat(&quot;Booking&quot;)" />
          <xsl:variable name="var:v3" select="userCSharp:StringConcat(string(s2:ObjectID/text()) , string(../../../../InputMessagePart_0/s2:ObjectPriceName/s2:PriceNameID/text()))" />
          <xsl:variable name="var:v4" select="userCSharp:LogicalEq(string(../../../../InputMessagePart_2/s2:Event/s2:ShowOnWeb/text()) , &quot;true&quot;)" />
          <xsl:variable name="var:v5" select="userCSharp:LogicalGt(string(../../../../InputMessagePart_2/s2:Event/s2:MaxParticipantNr/text()) , string(../../../../InputMessagePart_2/s2:Event/s2:TotalParticipantNr/text()))" />
          <xsl:variable name="var:v6" select="userCSharp:LogicalEq(string($var:v4) , string($var:v5))" />
          <xsl:variable name="var:v8" select="userCSharp:LogicalNot(string($var:v6))" />
          <xsl:variable name="var:v10" select="userCSharp:LogicalExistence(boolean(../../../../InputMessagePart_2/s2:Event/s2:PeriodStart))" />
          <xsl:variable name="var:v13" select="userCSharp:LogicalExistence(boolean(../../../../InputMessagePart_2/s2:Event/s2:PeriodEnd))" />
          <xsl:variable name="var:v16" select="userCSharp:LogicalExistence(boolean(../../../../InputMessagePart_2/s2:Event/s2:StatusID))" />
          <xsl:variable name="var:v18" select="userCSharp:LogicalEq(string(../../../../InputMessagePart_2/s2:Event/s2:StatusID/text()) , &quot;1&quot;)" />
          <ns0:Product>
            <ns0:Name>
              <xsl:value-of select="$var:v1" />
            </ns0:Name>
            <ns0:Type>
              <xsl:value-of select="$var:v2" />
            </ns0:Type>
            <ns0:SKU>
              <xsl:value-of select="../../../../InputMessagePart_2/s2:Event/s2:EventID/text()" />
            </ns0:SKU>
            <ns0:ParentSKU>
              <xsl:value-of select="$var:v3" />
            </ns0:ParentSKU>
            <ns0:ListPrice>
              <xsl:value-of select="../../../../InputMessagePart_0/s2:ObjectPriceName/s2:Price/text()" />
            </ns0:ListPrice>
            <xsl:if test="s2:CourseDescriptionShort">
              <ns0:ShortDescription>
                <xsl:value-of select="s2:CourseDescriptionShort/text()" />
              </ns0:ShortDescription>
            </xsl:if>
            <xsl:if test="s2:CourseDescription">
              <ns0:Description>
                <xsl:value-of select="s2:CourseDescription/text()" />
              </ns0:Description>
            </xsl:if>
            <xsl:if test="s2:ImageUrl">
              <ns0:Image>
                <xsl:value-of select="s2:ImageUrl/text()" />
              </ns0:Image>
            </xsl:if>
            <xsl:if test="string($var:v6)='true'">
              <xsl:variable name="var:v7" select="&quot;ACTIVE&quot;" />
              <ns0:Status>
                <xsl:value-of select="$var:v7" />
              </ns0:Status>
            </xsl:if>
            <xsl:if test="string($var:v8)='true'">
              <xsl:variable name="var:v9" select="&quot;INACTIVE&quot;" />
              <ns0:Status>
                <xsl:value-of select="$var:v9" />
              </ns0:Status>
            </xsl:if>
            <ns0:Attribute>
              <xsl:if test="string($var:v10)='true'">
                <xsl:variable name="var:v11" select="&quot;startdate&quot;" />
                <xsl:attribute name="id">
                  <xsl:value-of select="$var:v11" />
                </xsl:attribute>
              </xsl:if>
              <xsl:if test="string($var:v10)='true'">
                <xsl:variable name="var:v12" select="../../../../InputMessagePart_2/s2:Event/s2:PeriodStart/text()" />
                <xsl:value-of select="$var:v12" />
              </xsl:if>
            </ns0:Attribute>
            <ns0:Attribute>
              <xsl:if test="string($var:v13)='true'">
                <xsl:variable name="var:v14" select="&quot;enddate&quot;" />
                <xsl:attribute name="id">
                  <xsl:value-of select="$var:v14" />
                </xsl:attribute>
              </xsl:if>
              <xsl:if test="string($var:v13)='true'">
                <xsl:variable name="var:v15" select="../../../../InputMessagePart_2/s2:Event/s2:PeriodEnd/text()" />
                <xsl:value-of select="$var:v15" />
              </xsl:if>
            </ns0:Attribute>
            <ns0:Attribute>
              <xsl:if test="string($var:v16)='true'">
                <xsl:variable name="var:v17" select="&quot;occationstatus&quot;" />
                <xsl:attribute name="id">
                  <xsl:value-of select="$var:v17" />
                </xsl:attribute>
              </xsl:if>
              <xsl:if test="string($var:v18)='true'">
                <xsl:variable name="var:v19" select="&quot;OPEN&quot;" />
                <xsl:variable name="var:v20" select="string(../../../../InputMessagePart_2/s2:Event/s2:StatusID/text())" />
                <xsl:variable name="var:v21" select="userCSharp:LogicalEq($var:v20 , &quot;2&quot;)" />
                <xsl:if test="string($var:v21)='true'">
                  <xsl:variable name="var:v22" select="userCSharp:LogicalEq($var:v20 , &quot;3&quot;)" />
                  <xsl:if test="string($var:v22)='true'">
                    <xsl:variable name="var:v23" select="&quot;CLOSED&quot;" />
                    <xsl:variable name="var:v24" select="userCSharp:StringConcat(string($var:v19) , string($var:v19) , string($var:v23))" />
                    <xsl:value-of select="$var:v24" />
                  </xsl:if>
                </xsl:if>
              </xsl:if>
            </ns0:Attribute>
            <ns0:Attribute>
              <xsl:variable name="var:v30" select="&quot;staff&quot;" />
              <xsl:attribute name="id">
                <xsl:value-of select="$var:v30" />
              </xsl:attribute>
              <xsl:for-each select="../../../../InputMessagePart_3/s0:GetPersonnelObjectResponse/s0:GetPersonnelObjectResult">
                <xsl:variable name="var:v28" select="userCSharp:StringConcat (string(s0:ObjectName),&quot;; &quot;)"/>
                <xsl:value-of select="$var:v28" />
              </xsl:for-each>
            </ns0:Attribute>
            <xsl:for-each select="../../../../InputMessagePart_4/s2:GetLocationAddressResponse/s2:GetLocationAddressResult">
              <xsl:for-each select="s2:LocationAddress">
                <xsl:for-each select="s2:Name">
                  <xsl:variable name="var:v32" select="string(./text())" />
                  <xsl:variable name="var:v33" select="userCSharp:LogicalIsString($var:v32)" />
                  <ns0:Attribute>
                    <xsl:if test="string($var:v33)='true'">
                      <xsl:variable name="var:v34" select="&quot;location&quot;" />
                      <xsl:attribute name="id">
                        <xsl:value-of select="$var:v34" />
                      </xsl:attribute>
                    </xsl:if>
                    <xsl:if test="string($var:v33)='true'">
                      <xsl:variable name="var:v35" select="./text()" />
                      <xsl:value-of select="$var:v35" />
                    </xsl:if>
                  </ns0:Attribute>
                </xsl:for-each>
              </xsl:for-each>
            </xsl:for-each>
            <xsl:for-each select="../../../../InputMessagePart_2/s2:Event/s2:City">
              <xsl:variable name="var:v36" select="string(./text())" />
              <xsl:variable name="var:v37" select="userCSharp:LogicalIsString($var:v36)" />
              <ns0:Attribute>
                <xsl:if test="string($var:v37)='true'">
                  <xsl:variable name="var:v38" select="&quot;city&quot;" />
                  <xsl:attribute name="id">
                    <xsl:value-of select="$var:v38" />
                  </xsl:attribute>
                </xsl:if>
                <xsl:if test="string($var:v37)='true'">
                  <xsl:variable name="var:v39" select="./text()" />
                  <xsl:value-of select="$var:v39" />
                </xsl:if>
              </ns0:Attribute>
            </xsl:for-each>
          </ns0:Product>
        </xsl:for-each>
      </xsl:for-each>
    </ns0:Products>
  </xsl:template>
  <msxsl:script language="C#" implements-prefix="userCSharp"><![CDATA[
public string StringConcat(string param0, string param1, string param2)
{
   return param0 + param1 + param2;
}


public string StringConcat(string param0)
{
   return param0;
}


public string StringConcat(string param0, string param1)
{
   return param0 + param1;
}


public bool LogicalEq(string val1, string val2)
{
 bool ret = false;
 double d1 = 0;
 double d2 = 0;
 if (IsNumeric(val1, ref d1) && IsNumeric(val2, ref d2))
 {
  ret = d1 == d2;
 }
 else
 {
  ret = String.Compare(val1, val2, StringComparison.Ordinal) == 0;
 }
 return ret;
}


public bool LogicalGt(string val1, string val2)
{
 bool ret = false;
 double d1 = 0;
 double d2 = 0;
 if (IsNumeric(val1, ref d1) && IsNumeric(val2, ref d2))
 {
  ret = d1 > d2;
 }
 else
 {
  ret = String.Compare(val1, val2, StringComparison.Ordinal) > 0;
 }
 return ret;
}


public bool LogicalNot(string val)
{
 return !ValToBool(val);
}


public bool LogicalExistence(bool val)
{
 return val;
}


public bool LogicalIsString(string val)
{
 return (val != null && val !="");
}


public bool IsNumeric(string val)
{
 if (val == null)
 {
  return false;
 }
 double d = 0;
 return Double.TryParse(val, System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out d);
}

public bool IsNumeric(string val, ref double d)
{
 if (val == null)
 {
  return false;
 }
 return Double.TryParse(val, System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out d);
}

public bool ValToBool(string val)
{
 if (val != null)
 {
  if (string.Compare(val, bool.TrueString, StringComparison.OrdinalIgnoreCase) == 0)
  {
   return true;
  }
  if (string.Compare(val, bool.FalseString, StringComparison.OrdinalIgnoreCase) == 0)
  {
   return false;
  }
  val = val.Trim();
  if (string.Compare(val, bool.TrueString, StringComparison.OrdinalIgnoreCase) == 0)
  {
   return true;
  }
  if (string.Compare(val, bool.FalseString, StringComparison.OrdinalIgnoreCase) == 0)
  {
   return false;
  }
  double d = 0;
  if (IsNumeric(val, ref d))
  {
   return (d > 0);
  }
 }
 return false;
}


]]></msxsl:script>
</xsl:stylesheet>


Viewing all articles
Browse latest Browse all 872

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>