Is there any way to handle multiple input xmls in xslt? -
Is it possible to downgrade work done with XSLT? This means that I will have both the source XML and MAP XML loaded in XSLT. And in XSLT, without any rigid hard values, I should be able to read the map xml and apply the same on the source XML.
Source XML to be changed
Map XML
& lt; Root element orginalname = "book" ToTransform = "C_BOOKS" & gt; & Lt; ChildElement OrginalName = "Title" ToTransform = "C_TITLES" /> & Lt; ChildElement OrginalName = "Aurthor" ToTransform = "C_AURTHOR" /> & Lt; ChildElement OrginalName = "Publisher" ToTransform = "C_PUBLISHER" /> & Lt; / RootElement & gt;
The output should be XML: [after the transform]
& lt; C_BOOKS & gt; & Lt; C_TITLES & gt; C & lt; / C_TITLES & gt; & Lt; C_AURTHOR & gt; Balaguru Sami & lt; / C_AURTHOR & gt; & Lt; C_PUBLISHER & gt; Publisher's name & lt; / C_PUBLISHER & gt; & Lt; / C_BOOKS & gt;
Thanks in advance, Kannan Mohan
Use the map.xml as an XSLT stylesheet, and to change it. For example, you can write your map.xsl in such a way as:
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Xsl: stylesheet xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" & gt; & Lt; Xsl: template match = "book" & gt; & Lt; C_BOOKS & gt; & Lt; XSL: implemented-templates / & gt; & Lt; / C_BOOKS & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "title" & gt; & Lt; C_TITLES & gt; & Lt; XSL: implemented-templates / & gt; & Lt; / C_TITLES & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: Template Match = "Arthur" & gt; & Lt; C_AURTHOR & gt; & Lt; XSL: implemented-templates / & gt; & Lt; / C_AURTHOR & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: Template Match = "Publisher" & gt; & Lt; C_PUBLISHER & gt; & Lt; XSL: implemented-templates / & gt; & Lt; / C_PUBLISHER & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt;
And by using it you can actually get the results that you get.
Since your question is about multiple inputs, you can handle it with the document ()
function by using your example you can type map.xml
The file can also be loaded and can also create a simple stylesheet:
& lt; Xsl: stylesheet xmlns: xsl = "http: //www.w3.org/1999/XSL/Transform" version = "1.0" & gt; & Lt; Xsl: variable name = "map" = "document ('map.xml')" /> & Lt; Xsl: template match = "*" & gt; & Lt; Xsl: Select the variable name = "tag-name" = "name (.)" / & Gt; & Lt; Xsl: element name = "{$ map // '[[OrginalName = $ tag-name] / @ toTransform}" & gt; & Lt; XSL: implemented-templates / & gt; & Lt; / XSL: element & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt;
If any map.xml
will load the file in a variable, and that variable will use any tag as OrginalName
, its Compare the current node, and replace the tag with the corresponding name in the ToTransform
attribute. The xsl: element
tag creates a new element with the name passed as a feature. {...}
Expression is a attribute value template that will generate expression value within it, whose name element will be.
It is simple but still not very strong. It is best to see if the tag is supported or not, what to do if an unsupported tag is found (ignore, use the default tag result) . By the way it will fail with an error if it finds a tag in the source which is not supported in the map.xml
file.
Comments
Post a Comment