Combining two XML files using XSLT

I have 2 xml files that I need to combine with the stylesheet

<AssessmentInput> <ApplicationData>...</AppicationData> <MetricList>...</MetricList> </AssessmentInput> 

One of them is ApplicationData and the other is MetricList. that's what i did but it is nothing but how it should be

 <?xml version="1.0" encoding="ascii"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="xsl exslt"> <xsl:output omit-xml-declaration="yes" method="xml" encoding="UTF-8"/> <xsl:param name="ApplicationData" select="/"/> <xsl:param name="MetricList"/> <xsl:template match="/"> <xsl:apply-templates select="$ApplicationData/ApplicationData"/> </xsl:template> <xsl:template match="ApplicationData"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:apply-templates select="*"/> </xsl:copy> </xsl:template> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> 

Please help me. I have no experience with XSLT.

+6
source share
3 answers

Given the following input files:

ApplicationData.xml

 <?xml version="1.0" ?> <ApplicationData> Whatever data you have in here. </ApplicationData> 

MetricList.xml

 <?xml version="1.0" ?> <MetricList> Whatever list you have in here. </MetricList> 

AssessmentInput.xml

 <?xml version="1.0" ?> <AssessmentInput /> 

the following merge.xsl conversion applies to AssessmentInput.xml

 <?xml version="1.0" ?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/AssessmentInput"> <xsl:copy> <xsl:copy-of select="document('ApplicationData.xml')" /> <xsl:copy-of select="document('MetricList.xml')" /> </xsl:copy> </xsl:template> </xsl:transform> 

displays the correct result

 <?xml version="1.0" encoding="UTF-8"?> <AssessmentInput> <ApplicationData> Whatever data you have in here. </ApplicationData> <MetricList> Whatever list you have in here. </MetricList> </AssessmentInput> 
+8
source

You should replace your string as follows: -

 <xsl:param name="ApplicationData" select="/"/> <xsl:param name="MetricList"/> with this below line one: <xsl:variable name="Application_Data" select="document('Application_Data.xml')/ApplicationData"/> <xsl:variable name="'Metric_List" select="document('Application_Data.xml')/MetricList"/> 

I think this may help you.

0
source

Can Application_Data.xml in line

 select="document('Application_Data.xml')/ApplicationData"/> 

be the url? how

 select="document('../appfiles/Application_Data.xml')/ApplicationData"/> 
0
source

Source: https://habr.com/ru/post/954653/


All Articles