cancel
Showing results for 
Search instead for 
Did you mean: 

Question about XSLT Mapping with condition?

former_member203764
Participant
0 Kudos

Dear Gurus,

I have a simple Scenario: multiple mapping:  XML --> PI --> XML (step 1.) XML --> IDoc. (step 2.) 

The file structure Looks like:

MT_SourceFile

    record                       1..unbounded

        ReferNo                 1..1

        ContainerType       1..1

         ContainerNo          1..1

         Supplier                  1..1
         MaterialGroupNo    1..1

         DeliveryDate           1..1

         ...

At the first step I want to sort it by using XSLT-Mapping v1.0 according to the ContainerNo and the MaterialGroupNo is not empty and is an integer.

The sort works well, but the check empty and integer not.

Could you help me?

thanks a lot in advance!

Regards

Sara

Accepted Solutions (1)

Accepted Solutions (1)

former_member190293
Active Contributor
0 Kudos

Hi Sara!

To check if value is integer in XSLT 1.0 you can use this:

<xsl:if test = "floor($var) = $var" >

...

</xsl:if>

To check if node exists:

test="YourNodeName"

To check if node is not empty:

test="YourNodeName=''"

Regards, Evgeniy.

former_member203764
Participant
0 Kudos

Hi Evgeniy,

thank u for your reply!

I tested it. unforturnately it does not work.

I have also tested a lot:

string(number($var)) = 'NaN'

number($var) = $var

number($var) = number($var)

...

It must be solved by Java-enhancement?

nice weekend

Sara

former_member190293
Active Contributor
0 Kudos

Hi Sara!

I've tried it myself.

Source XML:

<?xml version="1.0"?>

<ns0:MT_SourceFile xmlns:ns0="urn://my_test">

     <record>

          <ContainerType>A</ContainerType>

          <ContainerNo>3</ContainerNo>

          <MaterialGroupNo>12.01</MaterialGroupNo>

     </record>

     <record>

          <ContainerType>A</ContainerType>

          <ContainerNo>2</ContainerNo>

     </record>

     <record>

          <ContainerType>B</ContainerType>

          <ContainerNo>8</ContainerNo>

          <MaterialGroupNo>01</MaterialGroupNo>

     </record>

     <record>

          <ContainerType>A</ContainerType>

          <ContainerNo>7</ContainerNo>

          <MaterialGroupNo>4</MaterialGroupNo>

     </record>

     <record>

          <ContainerType>B</ContainerType>

          <ContainerNo>1</ContainerNo>

          <MaterialGroupNo>A007</MaterialGroupNo>

     </record>

     <record>

          <ContainerType>A</ContainerType>

          <ContainerNo>4</ContainerNo>

          <MaterialGroupNo>100</MaterialGroupNo>

     </record>

</ns0:MT_SourceFile>

XSL transformation:

<?xml version="1.0" encoding="UTF-8"?>

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

                       version="1.0">

   

    <xsl:template match="/">

        <ns0:MT_DestFile xmlns:ns0="urn://my_test">

            <xsl:for-each select="//record[MaterialGroupNo and MaterialGroupNo != '' and                                              number(MaterialGroupNo) = number(MaterialGroupNo) and                                              floor(number(MaterialGroupNo)) = number(MaterialGroupNo)]">

                <xsl:sort select="ContainerNo"/>

                <record>

                    <xsl:copy-of select="./*"/>

                </record>

            </xsl:for-each>

        </ns0:MT_DestFile>   

    </xsl:template>

 

</xsl:stylesheet>

Result XML:

<?xml version="1.0" encoding="UTF-8"?>

<ns0:MT_DestFile xmlns:ns0="urn://my_test">

     <record>

          <ContainerType>A</ContainerType>

          <ContainerNo>4</ContainerNo>

          <MaterialGroupNo>100</MaterialGroupNo>

     </record>

     <record>

          <ContainerType>A</ContainerType>

          <ContainerNo>7</ContainerNo>

          <MaterialGroupNo>4</MaterialGroupNo>

     </record>

     <record>

          <ContainerType>B</ContainerType>

          <ContainerNo>8</ContainerNo>

          <MaterialGroupNo>01</MaterialGroupNo>

     </record>

</ns0:MT_DestFile>

Regards, Evgeniy.

former_member203764
Participant
0 Kudos

Hi Evgenity,

cool. very cool!

thank u very much!

Regards

Sara

former_member190293
Active Contributor
0 Kudos

Hi Sara!

Not at all!

Regards, Evgeniy.

Answers (1)

Answers (1)

former_member203764
Participant
0 Kudos

nobody can help me?

former_member186851
Active Contributor
0 Kudos

Hello Sara,

Post the XSLT used.

And for sorting and integer null check you can use normal graphical functions right why going with XSLT?