cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT mapping Help Required.

former_member331856
Participant
0 Kudos

XSLT mapping Help Required.

Hi Experts,


I am New to XSLT Mapping. I am practising the below Example:

InputXML File:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Persons111.xsl"?>

<ns0:MT_XSLT_Source xmlns:ns0="http://XYZ.com/gen">
<Person>
<FirstName>Anshul</FirstName>
<LastName>Chowdhary</LastName>
<Gender>Male</Gender>
<Address>
<Street>2nd Main</Street>
<Houseno>83/b</Houseno>
<City>Mysore</City>
</Address> </Person>
</ns0:MT_XSLT_Source>


XSL StyleSheet File:


<?xml version='1.0' encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://XYZ.com/Gen"

Xmlns:ns1=”http://XYZ.com/Test”>
<xsl:template match="/">
<ns1:MT_XSLT_Target>
<Title> <xsl:value-of select="ns0:MT_XSLT_Source/Person/Gender"/> </Title>
<Name> <xsl:value-of select="concat(concat(ns0:MT_XSLT_Source/Person/FirstName,' '), ns0:MT_XSLT_Source/Person/LastName)"/>

</Name>
<Street> <xsl:value-of select="concat(concat(ns0:Mt_XSLT_Source/Person/Address/Houseno,' '),

ns0:Mt_XSLT_Source/Person/Address/Street)"/> </Street>
<City> <xsl:value-of select="ns0:Mt_XSLT_Source/Person/Address/City"/> </City>
</ns1:MT_XSLT_Target>
</xsl:template>
</xsl:stylesheet>


The Desired Output shuold be:


<?xml version="1.0" encoding="UTF-8"?>
<ns1:MT_XSLT_Target xmlns:ns1="http://XYZ.com/Test">
<Title>Male</Title>
<Name>Anshul Chowdhary</Name>
<Street>83/b 2nd Main</Street>
<City>Mysore</City>
</ns1:MT_XSLT_Target>


I have refered the xsl in xml and i am getting the below Oupt in a Single line like this:
Anshul Chowdhary Male 2nd Main 83/b Mysore

I am Unable to display in Target XML Fomrat as shown above. Please check and do the needful.


Regards,
GIRIDHAR


Accepted Solutions (0)

Answers (4)

Answers (4)

former_member331856
Participant
0 Kudos

Hi Experts,

Thanks for the replies. I have checked the NameSpaces and corrrected them, but Still i am getting the output in a single line not getting as xml format.

Output in Borwser:

Anshul Chowdhary Male 2nd Main 83/b Mysore

Please check and post the output screenshot if possible.

Regards,

GIRIDHAR

peter_wallner2
Active Contributor
0 Kudos

Hello Giridhar,

If I use your source XML and my Stylesheet posted earlier I get this result:


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

<ns1:MT_XSLT_Target xmlns:ns1="http://XYZ.com/Test" xmlns:ns0="http://XYZ.com/gen">

    <Title>Male</Title>

    <Name>Anshul Chowdhary</Name>

    <Street>83/b 2nd Main</Street>

    <City>Mysore</City>

</ns1:MT_XSLT_Target>

Please try my stylesheet.

Best regards,

Peter

former_member331856
Participant
0 Kudos

Hi Peter,

Thanks for the reply.

Please clarify the below Issues:

1) How you are refering the xsl in xml.

2) How the Ouptut file is generated.

3) I am using Note pad for both xml and xsl. When i click on xml in browser i am not getting xml format.

Please explain me how how you are getting the Output.

Please do the needful.

Regards,

GIRIDHAR

Former Member
0 Kudos

Hi,

I got your problem .It's some problem with online test tools.

If you try this :XSLT Tryit Editor v1.0&lt;/title&gt;&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; hr...

you will get the o/p as below:

MaleAnshul Chowdhary83/b 2nd MainMysore

If you try this :XSLT Transformation - Online Toolz

you will get o/p as below:

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

<ns1:MT_XSLT_Target xmlns:ns1="http://XYZ.com/Test" xmlns:ns0="http://XYZ.com/gen">

<Title>Male</Title>

<Name>Anshul Chowdhary</Name>

<Street>83/b 2nd Main</Street>

<City>Mysore</City>

</ns1:MT_XSLT_Target>

You will receive second o/p,if you tried in PI as well.

Regards

Venkat

Former Member
0 Kudos

Hi,

I have used below for testing.

Input xml:

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

<?xml-stylesheet type="text/xsl" href="Persons111.xsl"?>

<ns0:MT_XSLT_Source xmlns:ns0="http://XYZ.com/gen">

<Person>

<FirstName>Anshul</FirstName>

<LastName>Chowdhary</LastName>

<Gender>Male</Gender>

<Address>

<Street>2nd Main</Street>

<Houseno>83/b</Houseno>

<City>Mysore</City>

</Address> </Person>

</ns0:MT_XSLT_Source>

xsl code:

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

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

    xmlns:ns1="http://XYZ.com/Test"> 

    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

    

    <xsl:template match="/"> 

        <ns1:MT_XSLT_Target> 

            <Title> <xsl:value-of select="ns0:MT_XSLT_Source/Person/Gender"/> </Title> 

            <Name> <xsl:value-of select="concat(concat(ns0:MT_XSLT_Source/Person/FirstName,' '), ns0:MT_XSLT_Source/Person/LastName)"/> 

                

            </Name> 

            <Street> <xsl:value-of select="concat(concat(/ns0:MT_XSLT_Source/Person/Address/Houseno,' '), 

                

                /ns0:MT_XSLT_Source/Person/Address/Street)"/> </Street> 

            <City> <xsl:value-of select="/ns0:MT_XSLT_Source/Person/Address/City"/> </City> 

        </ns1:MT_XSLT_Target> 

    </xsl:template> 

</xsl:stylesheet>

For testing in PI ,change the extension from .txt to .xsl and zip it and upload into PI as an imported archive .

Regards

Venkat

peter_wallner2
Active Contributor
0 Kudos

Hello Giridhar,

1) I am not referring the xml in the xsl. I am using Oxygen XML Editor for my scenarios.

2) Oxygen is generating the output file. Oxygen uses different processors like Xalan, etc.

You can also use Eclipse with an Add-on to do XSL transformations. There are also online tools but I am not sure of what quality they are (example shell-tools.net).

Have you tried using SAP PI like Venkat is suggesting?

I would still suggest another tool though for quick processing.

BEst regards,

Peter

Former Member
0 Kudos

Hello Giridhar ,

Use the below XSLT code

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

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

xmlns:ns1="http://XYZ.com/Test">

<xsl:template match="/">

  <ns1:MT_XSLT_Target>

    <Title>

     <xsl:value-of select="ns0:MT_XSLT_Source/Person/Gender"/>

    </Title>

    <Name>

     <xsl:value-of select="concat(concat(ns0:MT_XSLT_Source/Person/FirstName,' '), ns0:MT_XSLT_Source/Person/LastName)"/>

    </Name>

    <Street>

     <xsl:value-of select="concat(concat(ns0:Mt_XSLT_Source/Person/Address/Houseno,' '),ns0:Mt_XSLT_Source/Person/Address/Street)"/>

    </Street>

    <City>

     <xsl:value-of select="ns0:Mt_XSLT_Source/Person/Address/City"/>

    </City>

  </ns1:MT_XSLT_Target>

</xsl:template>

</xsl:stylesheet>

To find out whether your XSLT contains any errors  after importing the XSL try to display the code.IF youa re able to see your code then Syntax part is correct,if you are not able to view it then syntax its not correct.

In the above code the error you will face are with Line # 1 <?xml version="1.0" encoding="utf-8"?>

utf should be written in small letters and "1.0" should be enclosed between double quotes.

And xmlns should be in small letters ,in your case its Xmlns.Also pls check double quotes are properly used.

Better way to check is just open XSL file in NOTEPAD++ and use language XML.Then you can identify where exactly error is.

Regards,

Shri

peter_wallner2
Active Contributor
0 Kudos

Hello Giridhar,

Be careful: matching "ns0:Mt_XSLT_Source" is different than matching "ns0:MT_XSLT_Source".

Try this stylesheet, I adapted the one from you a little bit:


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

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

    xmlns:ns1="http://XYZ.com/Test">

    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

  

    <xsl:template match="/">

        <ns1:MT_XSLT_Target>

            <Title> <xsl:value-of select="ns0:MT_XSLT_Source/Person/Gender"/> </Title>

            <Name> <xsl:value-of select="concat(concat(ns0:MT_XSLT_Source/Person/FirstName,' '), ns0:MT_XSLT_Source/Person/LastName)"/>

              

            </Name>

            <Street> <xsl:value-of select="concat(concat(/ns0:MT_XSLT_Source/Person/Address/Houseno,' '),

              

                /ns0:MT_XSLT_Source/Person/Address/Street)"/> </Street>

            <City> <xsl:value-of select="/ns0:MT_XSLT_Source/Person/Address/City"/> </City>

        </ns1:MT_XSLT_Target>

    </xsl:template>

</xsl:stylesheet>

Best regards,

Peter

PS: I recommend also using www.stackoverflow.com for XSLT questions.

former_member331856
Participant
0 Kudos

Hi All,

I am alos using the XML Ouput Statement as below:

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> . But still i am not getinng the desired Output xml. Please check and do the needful.

Regards,

GIRIDHAR

Former Member
0 Kudos

Hi

There is a mismatch in the namespace name in xml and xsl file. in XML it is given as

http://XYZ.com/gen

But in XSL it is mentioned as

http://XYZ.com/Gen

Please correct the same and see you are getting the output or not.

Former Member
0 Kudos

Hi Indrajit

I need to speak to you urgently regarding a scenario could you kindly help.My number is 9007764930