cancel
Showing results for 
Search instead for 
Did you mean: 

Simple XSLT mapping fails

Dimitri
Active Contributor
0 Kudos

Dear,

I'm busy creating XSLT mappings and all looks good, except for one. That one keeps failing and I just do not see why.

I tried different things, but the target structure remains empty.

Incoming message

After the mapping

XSLT mapping code

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

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

                              xmlns:ns1=<namespace>

                              xmlns:ns0=<namespace>

<xsl:template match="/">

<ns1:MessageType>

<UserId><xsl:value-of select="*/*/AuditUser"/></UserId>

<OrganisationId><xsl:value-of select="*/*/MessageType/OrganisationId"/></OrganisationId>     

<OUIdArray>

<xsl:for-each select="*/*/MessageType/OUIdArray/OUId">

<OUId><xsl:value-of select="*/*/OUIdArray/OUId"/></OUId>

</xsl:for-each>

</OUIdArray>

   <DateFrom><xsl:value-of select="*/*/MessageType/DateFrom"/></DateFrom>

   <DateUntil><xsl:value-of select="*/*/MessageType/DateUntill"/></DateUntil>

</ns1:MessageType>

  </xsl:template>

</xsl:stylesheet>

Anyone a suggestion?

Thanks a lot.

Dimitri

Accepted Solutions (1)

Accepted Solutions (1)

iaki_vila
Active Contributor
0 Kudos

Hi Dimitri,

In your XSL i noticed that you have

<OUId><xsl:value-of select="*/*/OUIdArray/OUId"/></OUId>


instead of


<OUId><xsl:value-of select="*/*/MessageType/OUIdArray/OUId"/></OUId>

However, i would do in this way:

With this source  XML:


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

<root>

<OrganisationID> 1000</OrganisationID>

<OUIdArray>

<OUId>1 </OUId>

<OUId>2 </OUId>

<OUId>3 </OUId>

</OUIdArray>

<DateFrom>01.01.2010</DateFrom>

</root>

I would use this code XSL:


<OUIdArray>

                <xsl:for-each select="/root/OUIdArray/OUId">

                                <OUId>

                                                <xsl:value-of select="."/>

                               </OUId>

                </xsl:for-each>

</OUIdArray>

It's simplier under my point of view.

Hope this helps.

Regards.

Dimitri
Active Contributor
0 Kudos

Hi,

Thank you for the quick and correct answer!

Just one thing...

I see that a specific field in the target structure is marked as mandatory (occurrence = 1).

If I do not provide that field in the incoming messages, the XSLT mapping is performed without any error, but I expected to see and error somewhere, no?

Is there a possibility to check on mandatory fields or something else I could do to make sure a mandatory target field is filled or an error is raised?

Thanks.

Dimitri

iaki_vila
Active Contributor
0 Kudos

Hi Dimitri,

In my opinion, the issue that you expose now id rather to use SAP PI validation schema or any workaround of validation previous to the XSL mapping, in this way you will have in two places two functional actions (Validation and Mapping).

Regards,

Dimitri
Active Contributor
0 Kudos

Hi,

I fully agree, but just for my knowledge, is there any way to do that in the XSLT mapping?

Thanks.

Dimitri

iaki_vila
Active Contributor
0 Kudos

Hi Dimitri,

With only XSL and without call any java class, i dont know any smart way to do it, may be with xsl:if (XSLT &amp;lt;xsl:if&amp;gt; Element) and harcoding the mandatory fields. Perhaps, anybody knows a better way.

Regards.

Dimitri
Active Contributor
0 Kudos

Hi,

Thank you for the feedback...

Perhaps it is better to go for schema validation on communication channel level.

That is a standard way and I like those more.

Kind regards,

Dimitri

Answers (0)