Append xml param input to root node of target xml

309 views Asked by At

I have the source xml file as

<?xml version="1.0" encoding="UTF-8"?>
<ns0:entry xmlns:ns0="http://www.w3.org/2005/Atom">
<ns0:content type="application/xml">
    <ns0:properties>
        <ns0:x>qwerty</ns0:x>
        <ns0:y>OREQ</ns0:y>
        <ns0:y>abc</ns0:y>
    </ns0:properties>
</ns0:content>

And my updated xslt file after Lingamurthy's reply looks as below

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://www.w3.org/2005/Atom" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/> 
<xsl:param name="documentXML"/>
<xsl:variable name="temp" select="document($documentXML)"/>

<xsl:template match="ns0:entry">
  <xsl:copy>
    <xsl:copy-of select="$temp/ns0:entry/*" />
    <xsl:copy-of select="*"/>
</xsl:copy>
 </xsl:template>

 </xsl:stylesheet>

The parameter above documentXML is passed as

<?xml version="1.0" encoding="UTF-8"?>
<ns0:entry xmlns:ns0="http://www.w3.org/2005/Atom">
<ns0:link href="GetArtefactDetailsSet(ArtefactId)/EScHeaderSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/EScHeaderSet" title="application/atom+xml;type=feed" type="EScHeaderSet">
    <ns0:inline>
        <ns0:feed/>
    </ns0:inline>
</ns0:link>
</ns0:entry>

Note that all this process is being run in tibco and the isXMLDocument flag for documentXML parameter is true()

I am getting below error when running it [javax.xml.transform.TransformerException] occurred during XSLT transformation: javax.xml.transform.TransformerException: com.tibco.xml.xquery.ExprException: java.net.MalformedURLException: no protocol:

I have been stuck in this for few days need to get this done desperately. The resultant xml should be like this

<?xml version="1.0" encoding="UTF-8"?>
<ns0:entry xmlns:ns0="http://www.w3.org/2005/Atom">
<ns0:link href="GetArtefactDetailsSet(ArtefactId)/EScHeaderSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/EScHeaderSet" title="application/atom+xml;type=feed" type="EScHeaderSet">
    <ns0:inline>
        <ns0:feed/>
    </ns0:inline>
</ns0:link>
<ns0:content type="application/xml">
    <ns0:properties>
        <ns0:x>qwerty</ns0:x>
        <ns0:y>OREQ</ns0:y>
        <ns0:z>abc</ns0:z>
    </ns0:properties>
</ns0:content>
</ns0:entry>
1

There are 1 answers

9
Lingamurthy CS On BEST ANSWER

You are missing namespace declaration. Use the following XSLT, some corrections have been made:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://www.w3.org/2005/Atom" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="documentXML"/>
<xsl:template match="ns0:entry">
    <xsl:copy>
        <xsl:copy-of select="$documentXML/ns0:entry/*" />
        <xsl:copy-of select="*"/>
    </xsl:copy>
</xsl:template>
</xsl:stylesheet>