Custom XSLT — Need some assistance, please

Home Page Forums BizTalk 2004 – BizTalk 2010 Custom XSLT — Need some assistance, please

Viewing 1 reply thread
  • Author
    Posts
    • #13343

      A couple of questions:
      What does the output look like for the second instance?
      Do you want the <spec> element included or just the <Info> elements mapped
      In your sample you have indented the <Spec> elements but they are not child elements of the preceding <Info> element.
      Is there some relationship between the <Spec> element and preceding <Info> element that is derived from its position and does this relationship have to be maintained across the map?

    • #13344

      An alternative would be to change this line from the original XSLT:

      <xsl:for-each select=\”Detail/Info\”>
      To
      <xsl:for-each select=\”Detail//Info\”>

      • #13345

        Rich,

        Ignore my alternate suggestion, it won’t work as the <Spec> node will be dropped from the output.

        Does the <xsl:if> construct pick up all the <Spec> nodes or just the first one.

        You could also use:
        [code:1:856fdf2b37]<xsl:for-each select=\"Detail/Spec\">
        <Spec>
        <xsl:for-each select=\"Info\">
        <xsl:element name=\"{string(@Name)}\">
        <xsl:value-of select=\"string(@Value)\" />
        </xsl:element>
        </xsl:for-each>
        </Spec>
        </xsl:for-each> [/code:1:856fdf2b37]

        • #13346

          Hi all,

          I have a custom XSLT used within some maps I execute inside some orchestartions and the publishing app threw a kink at me with some XML changes I didn’t expect. Unfortunately, the XSLT was provided to me by a member of the boards here, as I’m not as well versed in XSLT as I’d like to be (but working on it).

          Here’s my situation:
          My incoming messages come into me in a name/value pair setup as below:
          [code:1:8a2c0b04e5]<Root>
          <Header>
          <Info Name=\"field1\" Value=\"value1\" />
          <Info Name=\"field2\" Value=\"value2\" />
          </Header>
          <Detail>
          <Info Name=\"field1\" Value=\"value1\" />
          <Info Name=\"field2\" Value=\"value2\" />
          </Detail>
          </Root>[/code:1:8a2c0b04e5][/code]

          The XSLT converts the XML to output the following:
          [code:1:8a2c0b04e5]<Root>
          <Header>
          <field1>value1</field1>
          <field2>value2</field2>
          </Header>
          <Detail>
          <field1>value1</field1>
          <field2>value2</field2>
          </Detail>
          </Root>[/code:1:8a2c0b04e5]

          The XSLT:
          [code:1:8a2c0b04e5]

          <xsl:template match=\"/\">
          <xsl:apply-templates select=\"/Root\" />
          </xsl:template>
          <xsl:template match=\"/Root\">
          <Root>
          <Header>
          <xsl:for-each select=\"Header/Info\">
          <xsl:element name=\"{string(@Name)}\">
          <xsl:value-of select=\"string(@Value)\" />
          </xsl:element>
          </xsl:for-each>
          </Header>
          <Detail>
          <xsl:for-each select=\"Detail/Info\">
          <xsl:element name=\"{string(@Name)}\">
          <xsl:value-of select=\"string(@Value)\" />
          </xsl:element>
          </xsl:for-each>
          </Detail>
          </Root>
          </xsl:template>

          [/code:1:8a2c0b04e5]

          Whew…now, here is the change that occurred in the incoming XML:
          [code:1:8a2c0b04e5]<Root>
          <Header>
          <Info Name=\"field1\" Value=\"value1\" />
          <Info Name=\"field2\" Value=\"value2\" />
          </Header>
          <Detail>
          <Info Name=\"field1\" Value=\"value1\" />
          <Spec>
          <Info Name=\"field1\" Value=\"value1\" />
          <Info Name=\"field2\" Value=\"value2\" />
          </Spec>
          <Info Name=\"field2\" Value=\"value2\" />
          <Spec>
          <Info Name=\"field1\" Value=\"value1\" />
          <Info Name=\"field2\" Value=\"value2\" />
          </Spec>
          </Detail>
          </Root>[/code:1:8a2c0b04e5]

          As seen above, the new elment of ‘Spec’ has been added. The current XSLT is not seeing this new element and therefore, is not creating the output with the new element nested in the XML where I’d like it to do so. Also, the ‘Spec’ element may or may not be in the feed so I need to only output the ‘Spec’ data if it’s in the incoming message…so I won’t be creating the element if it’s not in the incoming message.

          Can anybody see how I can make the necessary change to the XSLT to reach my goal?

          Thanks in advance!
          -Rich

          • #13347

            OK, looks like I got it….I did the following if any cares to see:
            [code:1:29576332f5]

            <xsl:if test=\"/Root/Detail/Spec\">
            <Spec>
            <xsl:for-each select=\"Detail/Spec/Info\">
            <xsl:element name=\"{string(@Name)}\">
            <xsl:value-of select=\"string(@Value)\" />
            </xsl:element>
            </xsl:for-each>
            </Spec>
            </xsl:if>

            [/code:1:29576332f5]

            Good times!

            Take care,
            -Rich

            • #13348

              Hi Greg, you were the one that helped me with the original XSLT, good to hear from you.

              I have my change working as needed and verified the ‘new’ output with the developer who will consume the data so I think all is well with what I have. But to answer your questions and to help me understand XSLT a little better, here you go…

              [quote:8e6b8e67a7]
              What does the output look like for the second instance?
              [/quote:8e6b8e67a7]Identical, aside from the ‘Spec’ element and child nodes. Some messages have them which I need to preserve, and other messages will not have the Spec element so I won’t need the output to contain the element.

              [quote:8e6b8e67a7]Do you want the <spec> element included or just the <Info> elements mapped[/quote:8e6b8e67a7]I need the Spec element included as well, a consumer of the modified data will require the format if it’s there.

              [quote:8e6b8e67a7]In your sample you have indented the <Spec> elements but they are not child elements of the preceding <Info> element.[/quote:8e6b8e67a7]Correct, so the change I used above works, as I don’t need it to particularly show in a certain order of the output message. As long as Spec remains a child of Detail, I’m golden.

              [quote:8e6b8e67a7]Is there some relationship between the <Spec> element and preceding <Info> element that is derived from its position and does this relationship have to be maintained across the map?[/quote:8e6b8e67a7]No, just that Spec remains the child of Detail is the only requirement.

              • #13349

                Just the first one, so my new output looks like:

                [code:1:31f9befa88]

                <Detail>
                <Field1>Value1</Field1>

                <Spec>
                <Field1>Value1</Field1>
                <Field2>Value2</Field2>
                </Spec>

                </Detail>

                [/code:1:31f9befa88]

Viewing 1 reply thread
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.