cancel
Showing results for 
Search instead for 
Did you mean: 

Generating multiple target xmls from one source xml using xslt mappings

Former Member
0 Kudos

Hi,

I need to create more than one xml file from one source xml file using xslt mappings in file to file scenario.

Can you please let me know how this can be achieved.

Thanks,

Rajesh

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Rajesh,

If you must use the XSL Transformation then you can find a nice simple example here. It's based on the Xalan XSLT Processor which to my knowledge is incorporated in PI7.1. I've not actually tried this but it makes for an interesting mapping case so please let us know the results:

[XSLT Split for multiple XML file output|http://abbeyworkshop.com/howto/xslt/xslt_split/index.html]

The XSL file will require a namespace addition:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:redirect="http://xml.apache.org/xalan/redirect" extension-element-prefixes="redirect" version="1.0">

The redirect prefix is used for the write tags in the XSL file.

The details cover the transformation of the source file:

1:<student_list>
   2:    <student id="1">
   3:        <name>George Washington</name>
   4:        <major>Politics</major>
   5:        <phone>312-123-4567</phone>
   6:        <email>gw_at_example.edu</email>
   7:    </student>
   8:    <student id="2">
   9:        <name>Janet Jones</name>
  10:        <major>Undeclared</major>
  11:        <phone>311-122-2233</phone>
  12:        <email>janetj_at_example.edu</email>
  13:    </student>
  14:    <student id="3">
  15:        <name>Joe Taylor</name>
  16:        <major>Engineering</major>
  17:        <phone>211-111-2333</phone>
  18:        <email>joe_at_example.edu</email>
  19:    </student>
  20:</student_list>

Using this transformation:

2:<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 3:    xmlns:redirect="http://xml.apache.org/xalan/redirect"
 4:    extension-element-prefixes="redirect"
 5:    version="1.0"
 6:>
 7:<xsl:output method="xml"/>
 8:
 9:<xsl:template match="/">
10:    <xsl:apply-templates />
11:</xsl:template>
12:
13:<xsl:template match="student_list">
14:    <xsl:apply-templates />
15:</xsl:template>
16:
17:<xsl:template match="student">
18:    <xsl:variable name="filename" select="concat(@id,'.xml')" />
19:    <redirect:write select="$filename">
20:        <student id="{@id}">
21:            <xsl:apply-templates />
22:        </student>
23:    </redirect:write>
24:</xsl:template>
25:
26:<xsl:template match="name | major | phone | email">
27:    <xsl:copy-of select="." />
28:</xsl:template>
29:
30:</xsl:stylesheet>

Former Member
0 Kudos

Hi,

You would be able to accomplish it using graphical mapping itself(multi-mapping) if there is no other reason for going to XSLT.

check this document,

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/90dcc6f4-0829-2d10-b0b2-c892473f1...

http://help.sap.com/saphelp_nw04/helpdata/en/21/6faf35c2d74295a3cb97f6f3ccf43c/content.htm

regards,

francis

Former Member
0 Kudos

Thanks for your response.

But I have to do this using xslt mappings only, not by graphical mapping.

Former Member
0 Kudos

Hi,

Chk this (below blog shows n:1 multimapping, this will help u in dng 1:n mapping ) :

/people/aleksey.popov2/blog/2010/09/23/xslt-multi-mapping-example

Thanks

Amit