creating repeating node data on output

Home Page Forums BizTalk 2004 – BizTalk 2010 creating repeating node data on output

Viewing 1 reply thread
  • Author
    Posts
    • #13318

      INPUT:

      <keys>
      <key>
      <name>first</name>
      <value>123</value>
      </key>
      <key>
      <name>second</name>
      <value>45678</value>
      </key>
      </keys>

      XSLT:
      <xsl:stylesheet version=\”1.0\” xmlns:xsl=\”http://www.w3.org/1999/XSL/Transform\”>

      <xsl:template match=\”/\”>
      <keysout>
      <xsl:apply-templates/>
      </keysout>
      </xsl:template>

      <xsl:template match=\”//key\”>
      <xsl:variable name=\”elname\”>
      <xsl:value-of select=\”name\”/>
      </xsl:variable>
      <xsl:element name=\”{$elname}\”>
      <xsl:value-of select=\”value\”/>
      </xsl:element>
      </xsl:template>

      </xsl:stylesheet>

      The trick above is making the element name a variable.

      OUTPUT:
      <keysout>
      <first>123</first>
      <second>45678</second>
      </keysout>

      I would suggest you write it all in native XSLT. We use Stylus Studio which has an XSLT debugger for all our complex maps. Then in Biztalk, click on the map grid, then set the \”Custom XSLT Path\” property to the name of your .xslt stylesheet. You could also try to use the Scripting functoid and use in-line XSLT.

      Neal Walters
      http://Biztalk-Training.com

      <?xml version=’1.0′?>
      <xsl:stylesheet version=\”1.0\” xmlns:xsl=\”http://www.w3.org/1999/XSL/Transform\”>

      <xsl:template match=\”/\”>
      <xsl:apply-templates/>
      </xsl:template>

      <xsl:template match=\”//key\”>
      <xsl:variable name=\”elname\”>
      <xsl:value-of select=\”name\”/>
      </xsl:variable>
      <xsl:element name=\”{$elname}\”>
      <xsl:value-of select=\”value\”/>
      </xsl:element>
      </xsl:template>

      </xsl:stylesheet>

      • #13319

        Probably one of those really easy things that I just keep missing: I have data coming from a variety of sources and need to create an output schema like:
        <root>
        <keys>
        <key name=\”first\” value=\”123\”/>
        <key name=\”second\” value=\”45678\”/>
        etc or
        <key>
        <name>first</name>
        <value>123</value>
        </key>
        <key>
        <name>second</name>
        <value> 45678</value>
        </key>

        Where the number of keys is only known during execution of the orchestration (or pipeline) ie it is not a constant known in advance.

        Getting the data from the sources is not a problem, but generating the repeating output nodes is??
        How can I accomplish this??

        Thanks in advance.

        Chuck

    • #13317

      I am not sure if Neal understood the question properly.

      Can we clarify what you wish to do?
      You say you are receiving data from a variety of sources. Is this a fixed number of sources and a fixed number of messages with a variable number of key elements in each.
      Do you have a variable number of sources each sending 1 message, i.e. some sources may or may not send a message.
      Do you have a variable number of messages i.e. some sources may send 0 to many messages.

      There a number of ways of doing this, depending on the input.

      You can create a map with multiple input messages and one out message, although this will only work in some circumstances.

      A more generic approach will be to use an aggregating pattern.
      Download Alan Smiths example Aggregating Convoy and check the code in the AddOrderScope:
      [url]http://geekswithblogs.net/asmith/articles/9778.aspx[/url]

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