title: Use XSLT to extract information from JSON and output format as JSON
body: <p>With some help, I have put in place the following script which takes a JSON file as a parameter and outputs it as an XML.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      exclude-result-prefixes="#all"
      version="3.0"&gt;
      &lt;xsl:param name="json" as="xs:string"&gt;
      [
         {
            "ID":"DWL",
            "profiles":[
               {
                  "firstName":"Contact",
                  "lastName":"Sample",
                  "emailAddresses":[
                     {
                        "emailAddress":"inactive@mailinator.com"
                     }
                  ]
               }
            ]
         },
         {
            "ID":"DWLK",
            "profiles":[
               {
                  "firstName":"Contact",
                  "lastName":"Sample",
                  "emailAddresses":[
                     {
                        "emailAddress":"sampltest@mailinator.com",
                        "primary":true
                     }
                  ]
               }
            ]
         }
      ] 
    &lt;/xsl:param&gt;
      &lt;xsl:template match="/" name="xsl:initial-template"&gt;
          &lt;xsl:sequence select="json-to-xml($json)"/&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>I need to modify the script in such a way to extract the ID, <code>profiles.FirstName</code>, and <code>profiles.emailAddresses</code> and also add an extra static field <code>origin</code>. The final output should be the following:</p>
  
  <pre><code>[  
     {  
        "ID":"DWL",
        "origin":"static",
        "profiles":[  
           {  
              "firstName":"Contact",
              "emailAddresses":[  
                 {  
                    "emailAddress":"sample@mailinator.com"
                 }
              ]
           }
        ]
     },
     {  
        "ID":"DWLK",
        "origin":"static",
        "profiles":[  
           {  
              "firstName":"Contact",
              "emailAddresses":[  
                 {  
                    "emailAddress":"sampltest@mailinator.com",
                    "primary":true
                 }
              ]
           }
        ]
     }
  ]
  </code></pre>