Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Inline
- This topic has 3 replies, 1 voice, and was last updated 9 years, 2 months ago by
community-content.
-
AuthorPosts
-
-
April 14, 2009 at 4:36 AM #22128
HiI’m new to XSLT. I’m trying to use inline XSLT in a biztalk map to generate a loop structure as the following:
my Source schema is:
*Root
*EDE1D01R
-ED0NR
*EDE1D02R
-EDT60
-ED0RNThe (*) is a record and (-) is an element. EDE1D01R and EDE1D02R are both set to 0-unbounded. The ED0NR in *EDE1D01R refers som elements which occur in
*EDE1D02R by the -ED0RN element.
Now i’m trying to map to this schema:
*Root
*ED01
-ED0NR
*ED02
-Message*ED01 is a record which is set to 0-unbounded and which has a child record *ED02 which also set to 0-unbounded. So my question is how to use xslt to
map so that *ED01 loops as many times as there are *EDE1D01R in source_schema but *ED02 will be created only for those -ED0NR who has a reference in
*EDE1D02R in the source schema. I wrote a nested for-loop in xslt as the following but it doesnt work. My code is:<xsl:for-each select=”//EDE1D01R”>
<xsl:for-each select=”//EDE1D02R”>
<xsl:if test=”//EDE1D01R/EDONR = current()/EDORN”>
<ED02>
<Message><xsl:value-of select=”current()/EDT60″ /></Message>
</ED02>
</xsl:if>
</xsl:for-each>
</xsl:for-each>this creates <ED02> in dest-file for all EDE1D02R and not only for those who have a referense.
Any help on that?
Thanks in advance.
-
April 14, 2009 at 12:56 PM #22136
I believe that the problem you are having has to do with the context within the “test” expression at the line:
<xsl:if test=”//EDE1D01R/EDONR = current()/EDORN”>
The “current” node in the test expression is not the EDE1D01R node. You can address this simply by using a variable. This should work:
<xsl:for-each select=“//EDE1D01R”>
<ED01>
<xsl:variable name=“D01Value” select=“ED0NR”/>
<ED0NR>
<xsl:value-of select=“$D01Value”/>
</ED0NR>
<xsl:for-each select=“//EDE1D02R[ED0RN = ED0NR]”>
<ED02>
<Message>
<xsl:value-of select=“current()/EDT60”/>
</Message>
</ED02>
</xsl:for-each>
</ED01>
</xsl:for-each>Since it seems that your map is just XSLT you may want to have your map just use an XSLT file rather than hide the XSLT in a functoid. Then you can use templates which are cleaner and faster. Here is an example that should work:
<xsl:stylesheet version=“1.0” xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”>
<xsl:template match=“/”>
<xsl:element name=“root”>
<xsl:apply-templates select=“//EDE1D01R”/>
</xsl:element>
</xsl:template><xsl:template match=“EDE1D01R”>
<xsl:variable name=“D01Value” select=“ED0NR”/>
<xsl:element name=“ED01”>
<xsl:element name=“ED0NR”>
<xsl:value-of select=“$D01Value”/>
</xsl:element>
<xsl:apply-templates select=“//EDE1D02R[ED0RN = $D01Value]”/>
</xsl:element>
</xsl:template><xsl:template match=“EDE1D02R”>
<xsl:element name=“ED02”>
<xsl:element name=“Message”>
<xsl:value-of select=“EDT60”/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>-
April 14, 2009 at 2:49 PM #22140
Oh, Tank u man alot.. it works 🙂
again, Many thanks. i was sitting with this for 3 days now!
-
April 14, 2009 at 3:00 PM #22141
Oh, Tank u man alot.. it works 🙂
I went for the first option you mentioned since i simplified my example here. This was a part of my map. I use other functoids in the map and this was the last thing to deal with.
again, Many thanks. i was sitting with this for 3 days now!
-
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.