cancel
Showing results for 
Search instead for 
Did you mean: 

How to get PI System ID in XSLT mapping

former_member217029
Participant
0 Kudos

Hello,

I would like pass user credentials based on the system Id in xslt mapping.

May i know how to get PI system id during run time?

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

former_member187447
Participant
0 Kudos

Hi Bhavana,

Try this

<xsl:variable name="SystemName" select="string(propertyUtil:getSAPSystemName())"/>

so using SystemName from above you can setup you credentials for different environment as

<User ID>

              <xsl:choose>

                              <xsl:when normalize-space($SystemName) = 'DEV'">

                                  <xsl:value-of select="'XXXXXX'"></xsl:value-of>

                               </xsl:when>

                              <xsl:when normalize-space($SystemName) = 'QA'">

                                   <xsl:value-of select="'YYYYY'"></xsl:value-of>

                               </xsl:when>

               <xsl:choose>

  

    <User ID>

Regards

Kalyan

former_member217029
Participant
0 Kudos

Hello Kalyan,

Thanks for your piece of code. Could you please suggest me where exactly this can go and fit in y above mentioned xsl program?

I am kind of not sure how to fit it.

Thanks

former_member187447
Participant
0 Kudos

Hi Bhavana,

Have you already created the PropertyUtil class as mentioned by others?

Regards

Kalyan.

former_member187447
Participant
0 Kudos

Have you already created this?

package com.utils;

public class PropertyUtil {

  public static String getSystemProperty(String prop){

  String retString = null;

  retString = (String)System.getProperty(prop);

  return retString;

  }

  public static String getSAPSystem(){

  String retString = null;

  retString = (String)System.getProperty("SAPSYSTEM");

  return retString;

  }

  public static String getSAPSystemName(){

  String retString = null;

  retString = (String)System.getProperty("SAPSYSTEMNAME");

  return retString;

  }

}

former_member217029
Participant
0 Kudos

Hello Kalyan,

I have question related to below statement to create .java & .class files.

Write the code, compile it; copy both the files(.java and .class) and paste it in folder according to the package created in the code.

Here, package is com.utils. So both the files (.java and .class) should go under folder Com/utils.


Once i have both the files where exactly i have to place these files? not sure where can i find out Com/utils folder.


Also do i need to deploy this in ESR?


Regards

former_member217029
Participant
0 Kudos

I have both .java & .class files generated and zipped to import under Imported Archive.

So now my question is how to make modifications to below my existing xsl program so that i can make if else condition based user/password passing

My xslt code is:

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

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

   <xsl:template match="/">

    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  

        <soap:Header>

            <ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">  

               <TokenUser>User1</TokenUser>

               <TokenPassword>pwd1</TokenPassword>

           </ValidationSoapHeader>

        </soap:Header>

        <soap:Body>

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

        </soap:Body>

    </soap:Envelope>

   </xsl:template>

</xsl:stylesheet>


Please help me how to pass user/password based on system ID whether it is QA or Prod.

former_member187447
Participant
0 Kudos

Com/utils is the package as you can see in the java code I have above. And ofcourse you need to deploy this in ESR as imported archive.

former_member187447
Participant
0 Kudos

I would suggest you go through the basics of XSLT in W3schools.com

You can place the code under <TokenUser></TokenUser> and <TokenPassword>pwd1</TokenPassword> as something like the following

<TokenUser>

              <xsl:choose>

                              <xsl:when normalize-space($SystemName) = 'DEV'">

                                  <xsl:value-of select="'User1'"></xsl:value-of>

                               </xsl:when>

                              <xsl:when normalize-space($SystemName) = 'QA'">

                                   <xsl:value-of select="'User2'"></xsl:value-of>

                               </xsl:when>

               <xsl:choose>

 

    </TokenUser>

<TokenPassword>

              <xsl:choose>

                              <xsl:when normalize-space($SystemName) = 'DEV'">

                                  <xsl:value-of select="'pwd1'"></xsl:value-of>

                               </xsl:when>

                              <xsl:when normalize-space($SystemName) = 'QA'">

                                   <xsl:value-of select="'pwd2'"></xsl:value-of>

                               </xsl:when>

               <xsl:choose>

 

    </TokenPassword>

Regards

Kalyan.

former_member217029
Participant
0 Kudos

Hello Kalyan,

I am getting error while saving saying that file is not valid and cursor stopping at below place where marked in red.

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

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

   <xsl:template match="/">

    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">   

        <soap:Header>

            <ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods"> 

            <xsl:variable name="SystemName" select="srting (propertyUtil:getSAPSystemName())"/>

    <TokenUser>

            <xsl:choose>

                              <xsl:when normalize-space($SystemName) = "PID">

                                <xsl:value-of select="'xyz'"></xsl:value-of>

                                </xsl:when>

                                <xsl:when normalize-space($SystemName) = "PIQ">

                                <xsl:value-of select="'ABC'"></xsl:value-of>

     </xsl:when>

            <xsl:choose>

               </TokenUser>

             

               <TokenPassword>

            <xsl:choose>

                              <xsl:when normalize-space($SystemName) = "PID">

                                <xsl:value-of select="'1234'"></xsl:value-of>

                                </xsl:when>

                                <xsl:when normalize-space($SystemName) = "PIQ">

                                <xsl:value-of select="'789'"></xsl:value-of>

     </xsl:when>

            <xsl:choose>

               </TokenPassword>

             

            </ValidationSoapHeader>

        </soap:Header>

        <soap:Body>

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

        </soap:Body>

    </soap:Envelope>

   </xsl:template>

</xsl:stylesheet>

Regards

Former Member
0 Kudos

it looks variable is not assigned correctly.

<xsl:variable name="SystemName" select="srting (propertyUtil:getSAPSystemName())"/>

it should be

<xsl:variable name="SystemName" select="string(propertyUtil:getSAPSystemName())"/>

former_member217029
Participant
0 Kudos

Hello Ram,

Good catch. Appreciated.

Even though i corrected it i am getting the same issue. Are you able to copy paste in your xmlspy and able to save it?

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

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

   <xsl:template match="/"> 

    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">   

        <soap:Header> 

            <ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods"> 

            <xsl:variable name="SystemName" select="string(propertyUtil:getSAPSystemName())"/>

     <TokenUser>

            <xsl:choose>

                              <xsl:when normalize-space($SystemName) = "PID">

                                <xsl:value-of select="'xyz'"></xsl:value-of>

                                </xsl:when>

                                <xsl:when normalize-space($SystemName) = "PIQ">

                                <xsl:value-of select="'ABC'"></xsl:value-of>

     </xsl:when>

            <xsl:choose>

               </TokenUser>

            

               <TokenPassword>

            <xsl:choose>

                              <xsl:when normalize-space($SystemName) = "PID">

                                <xsl:value-of select="'1234'"></xsl:value-of>

                                </xsl:when>

                                <xsl:when normalize-space($SystemName) = "PIQ">

                                <xsl:value-of select="'789'"></xsl:value-of>

     </xsl:when>

            <xsl:choose>

               </TokenPassword>

              

            </ValidationSoapHeader>

        </soap:Header>

        <soap:Body> 

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

        </soap:Body> 

    </soap:Envelope> 

   </xsl:template> 

</xsl:stylesheet> 

Snavi
Active Participant
0 Kudos

Hi,

check the xsl:when element in your xsl, the condition that you want should be in attribute 'test'

<xsl:when normalize-space($SystemName) = "PID"> should be replaced by <xsl:when test="normalize-space($SystemName) = 'PID'" >


and so on for other xsl:when elements in your xsl

Former Member
0 Kudos

use the below.

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

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

  <xsl:template match="/">

  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  

  <soap:Header>

  <ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">

  <xsl:variable name="SystemName" select="string(propertyUtil:getSAPSystemName())"/>

  <TokenUser>

  <xsl:choose>

  <xsl:when test='normalize-space($SystemName)="PID"'>

  <xsl:value-of select="'xyz'"></xsl:value-of>

  </xsl:when>

  <xsl:when test='normalize-space($SystemName)="PIQ"'>

  <xsl:value-of select="'ABC'"></xsl:value-of>

  </xsl:when>

  </xsl:choose>

  </TokenUser>

  <TokenPassword>

  <xsl:choose>

  <xsl:when test='normalize-space($SystemName)="PID"'>

  <xsl:value-of select="'1234'"></xsl:value-of>

  </xsl:when>

  <xsl:when test='normalize-space($SystemName)="PIQ"'>

  <xsl:value-of select="'789'"></xsl:value-of>

  </xsl:when>

  </xsl:choose>

  </TokenPassword>

  </ValidationSoapHeader>

  </soap:Header>

  <soap:Body>

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

  </soap:Body>

  </soap:Envelope>

  </xsl:template>

  </xsl:stylesheet>

former_member217029
Participant
0 Kudos

Hello Ramkumar,

Excellent. Thank you very much for correcting the code.

I have .java & .class files created and with me. So can i just directly import these 2 file along with xslt.zip file under Imported Archive from my local desktop ? or should i place these .java & .class files somewhere like mentioned below? This folder(Com/utils) i could see we are maintaining on some server so If i need to place these 2 java files there then while import to ESR, how to access to this remote folder which is not a local in my machine.

Write the code, compile it; copy both the files(.java and .class) and paste it in folder according to the package created in the code.

Here, package is com.utils. So both the files (.java and .class) should go under folder Com/utils.


Thanks

Former Member
0 Kudos

You need to import xsl and java code(.class) to ESR>import archives.

former_member190293
Active Contributor
0 Kudos

Hi Bhavana!

If you develop your java classes in Eclipse-based IDE (NWDS, for example) you could use Export-JAR file option to create .JAR file with your class on local drive and then import it as Imported Archive to ESR.

XSL transformation can be simply zipped and imported to ESR as well.

Regards, Evgeniy.

former_member190293
Active Contributor
0 Kudos

Also it's worth mention that you don't need any user class to call native java class function such as java.lang.System.getProperty(), for example.

1. In case of using external XSLT processor like Saxon you just define namespace as:

     xmlns:utils = "java:java.lang.System"

and call required function of that class in your XSL transformation:

     <xsl:value-of select="utils:getProperty('os.name')"/>

2. In case of using built-in Xalan proccessor of your PI system you define namespaces like this:

     xmlns:xalan="http://xml.apache.org/xalan"

     xmlns:utils="xalan://java.lang.System"

and perform the call:

     <xsl:value-of select="utils:getProperty('SAPSYSTEMNAME')"/>

That's all. No user-defined classes required.

Regards, Evgeniy.

former_member217029
Participant
0 Kudos

Hello,

Java developer created .java & .class files for the given java code and provided those files to me.

Imported xslt.zip and those 2 zipped java files under imported Archives.

So now when i execute operation mapping to test this, i am getting below error

        Transformer Configuration Exception occurred when loading XSLT XYZ_SOAP_Header.xsl; details: Cannot find external method 'com.utils.PropertyUtil.getSAPSystemName' (must be public).

See error logs for details    

To resolve this i have selected check box "Use SAP XML Toolkit" option in operation mapping. But now i am getting below error..

Call XSLT processor with stylsheet XYZ_SOAP_Header.xsl.

Method fatalError called, terminate transformation, because of

javax.xml.transform.TransformerException: com.sap.engine.lib.xsl.xpath.XPathException: Could not load class: com.utils.PropertyUtil required for extension library. -> com.sap.aii.ib.server.mapping.execution.MappingClassNotFoundException: com/utils/PropertyUtil.class

at com.sap.engine.lib.jaxp.TransformerImpl.transform(TransformerImpl.java:250)



Thanks

former_member217029
Participant
0 Kudos

Hello Ram,

Do i need to save these 2 java files(.JAVA & .class) to any specific folder other than my local directory to import into ESR ?

Because the error i am getting is trying to locate class "com.utils.PropertyUtil" and not found.

javax.xml.transform.TransformerException: com.sap.engine.lib.xsl.xpath.XPathException: Could not load class: com.utils.PropertyUtil required for extension library. -> com.sap.aii.ib.server.mapping.execution.MappingClassNotFoundException: com/utils/PropertyUtil.class


Thanks

former_member190293
Active Contributor
0 Kudos

Hi Bhavana!

1. Look at my post above - YOU DON'T NEED user class for your requirement.

2. If you don't use external XSLT transformer class - again, see my answer above. Try to define namespaces in your XSL transformation like this:

     xmlns:xalan="http://xml.apache.org/xalan"

     xmlns:utils="xalan://com.utils.PropertyUtil"

     ...

     <xsl:variable name="myvar" select="utils:getSAPSystemName()"/>

Regards, Evgeniy.

former_member217029
Participant
0 Kudos

Hello,

I have defined namespaces like you mentioned and this is what my xslt code now. But still i am getting error like below. Please suggest if anything need to be changed.

javax.xml.transform.TransformerException: com.sap.engine.lib.xsl.xpath.XPathException: Could not load class: xalan://com.utils.PropertyUtil required for extension library. -> com.sap.aii.ib.server.mapping.execution.MappingClassNotFoundException: com/utils/PropertyUtil.class

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

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan" xmlns:propertyUtil="xalan://com.utils.PropertyUtil">

  <xsl:template match="/">

  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

  <soap:Header>

  <ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">

  <xsl:variable name="SystemName" select="string(propertyUtil:getSAPSystemName())"/>

  <TokenUser>

  <xsl:choose>

  <xsl:when test='normalize-space($SystemName)="PID"'>

  <xsl:value-of select="'abc'"></xsl:value-of>

  </xsl:when>

  <xsl:when test='normalize-space($SystemName)="PIQ"'>

  <xsl:value-of select="'asd'"></xsl:value-of>

  </xsl:when>

  <xsl:when test='normalize-space($SystemName)="PIP"'>

  <xsl:value-of select="'xyz'"></xsl:value-of>

  </xsl:when>

  </xsl:choose>

  </TokenUser>

  <TokenPassword>

  <xsl:choose>

  <xsl:when test='normalize-space($SystemName)="PID"'>

  <xsl:value-of select="'1234'"></xsl:value-of>

  </xsl:when>

    <xsl:when test='normalize-space($SystemName)="PIQ"'>

  <xsl:value-of select="'6789'"></xsl:value-of>

  </xsl:when>

  <xsl:when test='normalize-space($SystemName)="PIP"'>

  <xsl:value-of select="'3456'"></xsl:value-of>

  </xsl:when>

  </xsl:choose>

  </TokenPassword>

  </ValidationSoapHeader>

  </soap:Header>

  <soap:Body>

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

  </soap:Body>

  </soap:Envelope>

  </xsl:template>

  </xsl:stylesheet>

former_member190293
Active Contributor
0 Kudos

Hi Bhavana!

Why don't you want to call java class method directly as I suggested? Just try it. Moreover, your custom java class is nothing more but a kind of wrapper which just calls the same methods you can call yourself from XSLT template.

Regards, Evgeniy.

former_member217029
Participant
0 Kudos

Hi,

I am quite new with xslt programming. Could you please help me to modify the provided xslt code to call java class method directly ?

Thanks much.

former_member182412
Active Contributor
0 Kudos

Hi Bhavana,

I have modified your XSLT.


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

<xsl:stylesheet version="1.0" xmlns:utils="xalan://java.lang.System" xmlns:xalan="http://xml.apache.org/xalan" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <xsl:template match="/">

      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

         <soap:Header>

            <ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">

               <xsl:variable name="SystemName" select="utils:getProperty(&apos;SAPSYSTEMNAME&apos;)"/>

               <TokenUser>

                  <xsl:choose>

                     <xsl:when test="normalize-space($SystemName)=&quot;POD&quot;">

                        <xsl:value-of select="&apos;abc&apos;">

                </xsl:value-of>

                     </xsl:when>

                     <xsl:when test="normalize-space($SystemName)=&quot;POQ&quot;">

                        <xsl:value-of select="&apos;asd&apos;">

                </xsl:value-of>

                     </xsl:when>

                     <xsl:when test="normalize-space($SystemName)=&quot;POP&quot;">

                        <xsl:value-of select="&apos;xyz&apos;">

                </xsl:value-of>

                     </xsl:when>

                  </xsl:choose>

               </TokenUser>

               <TokenPassword>

                  <xsl:choose>

                     <xsl:when test="normalize-space($SystemName)=&quot;POD&quot;">

                        <xsl:value-of select="&apos;1234&apos;">

                </xsl:value-of>

                     </xsl:when>

                     <xsl:when test="normalize-space($SystemName)=&quot;POQ&quot;">

                        <xsl:value-of select="&apos;6789&apos;">

                </xsl:value-of>

                     </xsl:when>

                     <xsl:when test="normalize-space($SystemName)=&quot;POP&quot;">

                        <xsl:value-of select="&apos;3456&apos;">

                </xsl:value-of>

                     </xsl:when>

                  </xsl:choose>

               </TokenPassword>

            </ValidationSoapHeader>

         </soap:Header>

         <soap:Body>

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

         </soap:Body>

      </soap:Envelope>

   </xsl:template>

</xsl:stylesheet>

Test:

Regards,

Praveen.

former_member190293
Active Contributor
0 Kudos

Hi Bhavana!

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

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

          xmlns:propertyUtil="xalan://java.lang.System">

 

     <xsl:variable name="SystemName" select="normalize-space(propertyUtil:getProperty('SAPSYSTEMNAME'))"/>

     <xsl:template match="/">

          <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                     xmlns:xsd="http://www.w3.org/2001/XMLSchema"                     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

               <soap:Header>

                    <ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">

                         <TokenUser>

                              <xsl:choose>

                                   <xsl:when test="$SystemName='PID'">

                                        <xsl:value-of select="'abc'"></xsl:value-of>

                                   </xsl:when>

                                   <xsl:when test="$SystemName='PIQ'">

                                        <xsl:value-of select="'asd'"></xsl:value-of>

                                   </xsl:when>

                                   <xsl:when test="$SystemName='PIP'">

                                        <xsl:value-of select="'xyz'"></xsl:value-of>

                                   </xsl:when>

                              </xsl:choose>

                         </TokenUser>

                         <TokenPassword>

                              <xsl:choose>

                                   <xsl:when test="$SystemName='PID'">

                                        <xsl:value-of select="'1234'"></xsl:value-of>

                                   </xsl:when>

                                   <xsl:when test="$SystemName='PIQ'">

                                        <xsl:value-of select="'6789'"></xsl:value-of>

                                   </xsl:when>

                                   <xsl:when test="$SystemName='PIP'">

                                        <xsl:value-of select="'3456'"></xsl:value-of>

                                   </xsl:when>

                              </xsl:choose>

                         </TokenPassword>

                    </ValidationSoapHeader>

               </soap:Header>

               <soap:Body>

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

               </soap:Body>

          </soap:Envelope>

     </xsl:template>

</xsl:stylesheet>

It's no need to call "normalize-space()" function in all of "when" branches. You can do it once when assigning value to your variable.

Regards, Evgeniy.

former_member217029
Participant
0 Kudos

Thank you Evgeniy & Praveen for your help. It worked !

Answers (3)

Answers (3)

former_member217029
Participant
0 Kudos

I am using this xslt code & java code to generate .class & .java. Please let me know if am missing anything.

XSLT code:

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

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

  <xsl:template match="/">

  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 

  <soap:Header>

  <ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">

  <xsl:variable name="SystemName" select="string(propertyUtil:getSAPSystemName())"/>

  <TokenUser>

  <xsl:choose>

  <xsl:when test='normalize-space($SystemName)="PID"'>

  <xsl:value-of select="'abc'"></xsl:value-of>

  </xsl:when>

  <xsl:when test='normalize-space($SystemName)="PIQ"'>

  <xsl:value-of select="'asd'"></xsl:value-of>

  </xsl:when>

  <xsl:when test='normalize-space($SystemName)="PIP"'>

  <xsl:value-of select="'xyz'"></xsl:value-of>

  </xsl:when>

  </xsl:choose>

  </TokenUser>

  <TokenPassword>

  <xsl:choose>

  <xsl:when test='normalize-space($SystemName)="PID"'>

  <xsl:value-of select="'1234'"></xsl:value-of>

  </xsl:when>

    <xsl:when test='normalize-space($SystemName)="PIQ"'>

  <xsl:value-of select="'6789'"></xsl:value-of>

  </xsl:when>

  <xsl:when test='normalize-space($SystemName)="PIP"'>

  <xsl:value-of select="'3456'"></xsl:value-of>

  </xsl:when>

  </xsl:choose>

  </TokenPassword>

  </ValidationSoapHeader>

  </soap:Header>

  <soap:Body>

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

  </soap:Body>

  </soap:Envelope>

  </xsl:template>

  </xsl:stylesheet>

Java code to create .java & .class

package com.utils;

 

public class PropertyUtil {

  public static String getSystemProperty(String prop){

  String retString = null;

  retString = (String)System.getProperty(prop);

  return retString;

  }

  public static String getSAPSystem(){

  String retString = null;

  retString = (String)System.getProperty("SAPSYSTEM");

  return retString;

  }

  public static String getSAPSystemName(){

  String retString = null;

  retString = (String)System.getProperty("SAPSYSTEMNAME");

  return retString;

  }

}

former_member190293
Active Contributor
0 Kudos

Hi Bhavana!

As Ramkumar has already mentioned above you should use XSL with java extensions.

Create java class with static methods and call the required method within your xsl transformation.

Add namespace definition to your XSLT:

xmlns:myjava="com.company.xpi.mapping.xslt.XSLTUtils", where namespace name is the full qualified path to your java class including package name.

Call your java method:

<xsl:variable name="Var1" select="myjava:MyMethod()"/>, where "MyMethod()" is the required static method of your class.

By the way, the same approach is used to call lookups in XSL transformations.

Regards, Evgeniy.

Former Member
0 Kudos

refer the blog, you can use the method getSAPsystemName()

former_member217029
Participant
0 Kudos

Hello,

My exact requirement here is I am using xslt mapping to add soap header(User/Password) during run time. I have to pass user/password credentials to soap header based on the system name based on QA or PROD.

My xslt code is:

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

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

   <xsl:template match="/"> 

    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">   

        <soap:Header> 

            <ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">   

               <TokenUser>User1</TokenUser>

               <TokenPassword>pwd1</TokenPassword>

           </ValidationSoapHeader>

        </soap:Header>

        <soap:Body> 

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

        </soap:Body> 

    </soap:Envelope> 

   </xsl:template> 

</xsl:stylesheet> 

So where exactly i have to introduce the xsl code in this to make a if else condition to pass user/password based on sap system id?