cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT Mapping issue. If condition.

Former Member
0 Kudos

Hi,

A and B are in Source Structure. "C" is in Target Structure.

If "A" value has between 5001 and 6999 then pass "B" to C.

How to do this in XSLT map?

Thanks

Deepthi

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

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

<xsl:for-each select="POS/Detail">

<xsl:if test="(POS/Detail/FieldA &gt; 5000) and (POS/Detail/FieldA &lt; 7000)">

<xsl:call-template name="insert_E1WPF02">

<xsl:with-param name="ReferenceNo"/>

<xsl:with-param name="ItemNo"/>

<xsl:with-param name="Amount"/>

</xsl:call-template>

</xsl:if>

</xsl:for-each>

<xsl:template name="insert_E1WPF02" match="/">

<xsl:param name="ItemNo"/>

<xsl:param name="Amount"/>

<xsl:param name="RefernceNo"/>

<ZUONR>

<xsl:value-of select="$ReferenceNo[$ItemNo&gt;'5000' and $ItemNo&lt;'7000']"/>

</ZUONR>

<POSNR>

<xsl:value-of select="$ItemNo"/>

</POSNR>

<WRBTR>

<xsl:value-of select="$Ammount"/>

</WRBTR>

</xsl:template>

</xsl:stylesheet>

former_member200962
Active Contributor
0 Kudos

Hi,

A and B are in Source Structure. "C" is in Target Structure.
If "A" value has between 5001 and 6999 then pass "B" to C.

If only the above condition has to be satisfied then you dont need to call a template, use a parameter etc just work on the below code:

<xsl:for-each select="POS/Detail">
<xsl:if test="(POS/Detail/FieldA &gt; 5000) and (POS/Detail/FieldA &lt; 7000)">
<C>
<xsl:value-of select="POS/Detail/FieldB"/>
</C>
</xsl:if>
</xsl:for-each>

Above code is assuming that Detail node is under POS but not under Header

Regards,

Abhishek.

Former Member
0 Kudos

Hi Abhishek,

I need to pass the result to the parameter "ReferenceNo". This code is already in production.

I just want to insert this condition.

Once I pass the value to "ReferenceNo" . It will pass the value to Field ZUONR which is the Idoc Field.

Can you please suggest me how I can pass the resultant value to the parameter "ReferenceNo".

former_member200962
Active Contributor
0 Kudos

Hi,

Please understand the steps done in the code before you try it:)

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

<xsl:for-each select="POS/Detail">
<xsl:if test="(POS/Detail/FieldA &gt; 5000) and (POS/Detail/FieldA &lt; 7000)">
<xsl:call-template name="insert_E1WPF02">
    <xsl:with-param name="ReferenceNo" />
</xsl:call-template>
</xsl:if>
</xsl:for-each>

<xsl:template name="insert_E1WPF02" match="/">
<xsl:param name="RefernceNo" select="POS/Detail/FieldB" />
<C>
<xsl:value-of select="$ReferenceNo"/>
</C>
</xsl:template>

</xsl:stylesheet>

Regards,

Abhishek.

Former Member
0 Kudos

Hi Abhishek,

The condition is working partly.

The problem here is I will be getting any values in Detail/FieldA. But I need to pass FieldB only when FieldA >5000 and <7000.

Example: consider below two cases.

Case1:

if FieldA gets value like 3000 (Since it is <5000) then I need to pass only FieldA and I should not pass FieldB.

Case2:

- If FieldA gets value like 5300 (Since it is >5000) I need to pass both FieldA and FieldB.

The code which you specified is working only for case 2. But it is not working for Case1.

Any suggestions please.

Thanks

Deepthi.

Former Member
0 Kudos

Code:

-


- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

- <xsl:for-each select="POS/Detail">

- <xsl:if test="(POS/Detail/FieldA > 5000) and (POS/Detail/FieldA < 7000)">

- <xsl:call-template name="insert_E1WPF02">

<xsl:with-param name="ReferenceNo" />

<xsl:with-param name="ItemNo" />

<xsl:with-param name="Amount" />

</xsl:call-template>

</xsl:if>

</xsl:for-each>

- <xsl:template name="insert_E1WPF02" match="/">

<xsl:param name="ItemNo" />

<xsl:param name="Amount" />

<xsl:param name="RefernceNo" select="POS/Detail/FieldB" />

- <ZUONR>

<xsl:value-of select="$ReferenceNo" />

</ZUONR>

- <POSNR>

<xsl:value-of select="$ItemNo" />

</POSNR>

- <WRBTR>

<xsl:value-of select="$Ammount" />

</WRBTR>

</xsl:template>

</xsl:stylesheet>

I Cannot use <xsl:template name="insert_E1WPF02> twice because it is creating 2 E1WPF02 Segments in Idoc for each transaction which is not correct.

former_member200962
Active Contributor
0 Kudos

Hi,

<xsl:if test=("A > 5000" and "A < 7000")>

The above format is wrong...use the below syntax:

<xsl:if test="(A &gt; 5000 and A &lt; 7000)">

For more reference view the example here: http://www.w3schools.com/xsl/el_if.asp

Also check your with-param declaration: http://www.w3schools.com/xsl/el_with-param.asp

Regards,

Abhishek.

Edited by: abhishek salvi on Apr 7, 2009 8:50 AM

Shabarish_Nair
Active Contributor
0 Kudos

& gt; and & lt;

thats what i meant but seems this editor changes it to > and < if i dont put that white space after the &

Former Member
0 Kudos

It's not working. It is showing below error in XMLSPY.

XSLT 1.0 : Debugging Error : Unexpected element

<xsl:if

-


Code: I just tried for &gt; 5000----


<xsl:for-each select="POS/Detail">

<xsl:call-template name="insert_E1WPF02">

xsl:with-param name="ItemNo" select="./FieldA"

<xsl:if test="(./Field1 &gt; 5000">

<C>

<xsl:with-param name="ReferenceNo" select="./Field2" />

</C>

</xsl:if>

<xsl:with-param name="Ammount" select="./Field3"/>

</xsl:call-template>

Can I insert IF statement in between the template?

Former Member
0 Kudos

Lines from your code :

xsl:with-param name="ItemNo" select="./FieldA"

<xsl:if test="(./Field1 &gt; 5000">

If you have pasted the exact code and is not a typo error, then the above lines have syntactical errors(First line enclose in braces representing the tag and in the if condition there is an extra '(' ). Correct them and check if it is still giving the error.

Edited by: BRREDDY on Apr 7, 2009 10:27 AM

Shabarish_Nair
Active Contributor
0 Kudos

>

> Hi,

>

> A and B are in Source Structure. "C" is in Target Structure.

>

> If "A" value has between 5001 and 6999 then pass "B" to C.

>

> How to do this in XSLT map?

>

> Thanks

> Deepthi

<xsl:if test=("A &gt; 5000" and "A &lt; 7000")>
<C>
<xsl:value-of select="B"/>
</C>
</xsl:if>

Former Member
0 Kudos

Hi Shabharish,

It's not working.

Source Structure looks like below.

<POS>

<HEADER>

- <Field1>

- <Field2>

<Detail>

-- <FieldA>

-- <FieldB>

-- <Field3>

</Detail>

</POS>

XSLT map Code:

-


<xsl:for-each select="POS/Detail">

xsl:with-param name="ItemNo" select="./FieldA"

<xsl:if test=("./FieldA > 5000" and "./FieldA < 7000")>

<C>

<xsl:with-param name="ReferenceNo" select="./FieldB" />

</C>

</xsl:if>

<xsl:with-param name="Ammount" select="./Field3"/>

Looks like some syntax error.? please suggest.

Shabarish_Nair
Active Contributor
0 Kudos

try

<xsl:if test=("./FieldA > 5000 and ./FieldA < 7000")>