0

My input XML is as below:

<?xml version="1.0" encoding="UTF-8"?>
<PQ>
   <PQGetClaimAttachment>
      <USERID>XXX</USERID>
      <PASSWORD>XXX</PASSWORD>
      <hostAddress>XXX</hostAddress>
      <businessArea>CS2XAA</businessArea>
      <sourceType>2XSRCTYP</sourceType>
      <operator>GT</operator>
      <lookupDate>2015-01-01T00.00.00.000000+05:30</lookupDate>
   </PQGetClaimAttachment>
</PQ>

I want to convert the above xml to the below one using XSLT:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<lookupInstances xmlns="http://www.tech.com/awd/rest/v1" name="XYZ">
  <lookupParameters>
    <lookupParameter name="businessArea">CS2XAA</lookupParameter>
    <lookupParameter name="type">2XSRCTYP</lookupParameter>
    <lookupParameter name="OPER">GT</lookupParameter>
    <lookupParameter name="LDAT">2015-01-01T00.00.00.000000+05:30</lookupParameter>
  </lookupParameters>
</lookupInstances>

I am using the following XSLT , but it's not giving me the desired output XML.

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

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*" />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="/">
            <lookupInstances xmlns="http://www.tech.com/awd/rest/v1"
                name="XYZ">
                <lookupParameters>
                    <lookupParameter businessArea="{//businessArea}" />
                    <lookupParameter type="{//sourceType}" />
                    <lookupParameter OPER="{//operator}" />
                    <lookupParameter LDAT="{//lookupDate}" />
                </lookupParameters>
            </lookupInstances>
    </xsl:template>

</xsl:stylesheet>

Could any one please let me know where I am doing the mistake?

1 Answer 1

1

If you want the output to have name="businessArea" attributes, it makes no sense to give them businessArea="" attributes.

This should do what you need:

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

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*" />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="/">
            <lookupInstances xmlns="http://www.tech.com/awd/rest/v1"
                name="XYZ">
                <lookupParameters>
                    <lookupParameter name="businessArea">
                         <xsl:value-of select="PQ/PQGetClaimAttachment/businessArea" />
                    </lookupParameter>
                    <lookupParameter name="type">
                         <xsl:value-of select="PQ/PQGetClaimAttachment/sourceType" />
                    </lookupParameter>
                    <lookupParameter name="OPER">
                         <xsl:value-of select="PQ/PQGetClaimAttachment/operator" />
                    </lookupParameter>
                    <lookupParameter name="LDAT">
                         <xsl:value-of select="PQ/PQGetClaimAttachment/lookupDate" />
                    </lookupParameter>
                </lookupParameters>
            </lookupInstances>
    </xsl:template>

</xsl:stylesheet>
Sign up to request clarification or add additional context in comments.

1 Comment

That's perfect..!! +1 for quick response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.