title: transform and combine multiple xml documents
body: <p>I have a <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1175133" rel="nofollow noreferrer">requirement</a> to host a NuGet repository under Apache on Linux. The design is fairly constrained and requires that the Packages feed be stored as a static file. An example of the required output format is here: <a href="http://chocolatey.org/api/v2/Packages" rel="nofollow noreferrer">http://chocolatey.org/api/v2/Packages</a>.</p>
  
  <p>I am attempting to generate this document from the *.nuspec files found inside the *.nupkg archives like so:</p>
  
  <pre class="lang-bash prettyprint-override"><code>#!/bin/bash
  
  #for pkg in nxlog git.install; do
  #  curl -L http://chocolatey.org/api/v2/package/$pkg -o $pkg.nupkg
  #done
  
  unzip "*.nupkg" "*.nuspec"
  xsltproc transform.xsl *.nuspec &gt; Packages
  rm -f *.nuspec
  </code></pre>
  
  <p>So far, the <strong>incorrect</strong> transform xslt looks like this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:output omit-xml-declaration="yes" indent="yes" /&gt;
    &lt;feed xml:base="http://gallery-host/api/v2/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom"&gt;
      &lt;title type="text"&gt;Packages&lt;/title&gt;
      &lt;id&gt;http://gallery-host/api/v2/Packages&lt;/id&gt;
      &lt;updated&gt;&lt;/updated&gt;
      &lt;link rel="self" title="Packages" href="Packages" /&gt;
      &lt;xsl:apply-templates /&gt;
    &lt;/feed&gt;
    &lt;xsl:template match="metadata"&gt;
      &lt;entry&gt;
        &lt;id&gt;&lt;xsl:value-of select="id"/&gt;&lt;/id&gt;
        &lt;title type="text"&gt;&lt;xsl:value-of select="title"/&gt;&lt;/title&gt;
        &lt;summary type="text"&gt;&lt;xsl:value-of select="summary"/&gt;&lt;/summary&gt;
        &lt;updated&gt;&lt;/updated&gt;
        &lt;author&gt;
          &lt;name&gt;&lt;xsl:value-of select="authors"/&gt;&lt;/name&gt;
        &lt;/author&gt;
        &lt;link rel="edit-media" title="V2FeedPackage"&gt;
          &lt;xsl:attribute name="href"&gt;Packages(Id='&lt;xsl:value-of select="id"/&gt;',Version='&lt;xsl:value-of select="version"/&gt;')/$value&lt;/xsl:attribute&gt;
        &lt;/link&gt;
        &lt;link rel="edit" title="V2FeedPackage"&gt;
          &lt;xsl:attribute name="href"&gt;Packages(Id='&lt;xsl:value-of select="id"/&gt;',Version='&lt;xsl:value-of select="version"/&gt;')&lt;/xsl:attribute&gt;
        &lt;/link&gt;
        &lt;category term="NuGetGallery.V2FeedPackage" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /&gt;
        &lt;content type="application/zip"&gt;
          &lt;xsl:attribute name="src"&gt;http://chocolatey.org/api/v2/package/&lt;xsl:value-of select="id"/&gt;/&lt;xsl:value-of select="version"/&gt;&lt;/xsl:attribute&gt;
        &lt;/content&gt;
        &lt;m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"&gt;
          &lt;d:Version&gt;&lt;xsl:value-of select="version"/&gt;&lt;/d:Version&gt;
          &lt;d:Copyright&gt;&lt;xsl:value-of select="copyright"/&gt;&lt;/d:Copyright&gt;
          &lt;!--
          &lt;d:Created m:type="Edm.DateTime"&gt;&lt;/d:Created&gt;
          &lt;d:Dependencies&gt;&lt;/d:Dependencies&gt;
          --&gt;
          &lt;d:Description&gt;&lt;xsl:value-of select="description"/&gt;&lt;/d:Description&gt;
          &lt;!--
          &lt;d:DownloadCount m:type="Edm.Int32"&gt;&lt;/d:DownloadCount&gt;
          --&gt;
          &lt;d:GalleryDetailsUrl&gt;http://gallery-host/packages/&lt;xsl:value-of select="id"/&gt;/&lt;xsl:value-of select="version"/&gt;&lt;/d:GalleryDetailsUrl&gt;
          &lt;d:IconUrl&gt;&lt;xsl:value-of select="iconUrl"/&gt;&lt;/d:IconUrl&gt;
          &lt;!--
          &lt;d:IsLatestVersion m:type="Edm.Boolean"&gt;&lt;/d:IsLatestVersion&gt;
          &lt;d:IsAbsoluteLatestVersion m:type="Edm.Boolean"&gt;&lt;/d:IsAbsoluteLatestVersion&gt;
          &lt;d:IsPrerelease m:type="Edm.Boolean"&gt;&lt;/d:IsPrerelease&gt;
          &lt;d:Language m:null="true"&gt;&lt;/d:Language&gt;
          &lt;d:Published m:type="Edm.DateTime"&gt;&lt;/d:Published&gt;
          --&gt;
          &lt;d:LicenseUrl&gt;&lt;xsl:value-of select="licenseUrl"/&gt;&lt;/d:LicenseUrl&gt;
          &lt;!--
          &lt;d:PackageHash&gt;&lt;/d:PackageHash&gt;
          &lt;d:PackageHashAlgorithm&gt;&lt;/d:PackageHashAlgorithm&gt;
          &lt;d:PackageSize m:type="Edm.Int64"&gt;&lt;/d:PackageSize&gt;
          --&gt;
          &lt;d:ProjectUrl&gt;&lt;xsl:value-of select="projectUrl"/&gt;&lt;/d:ProjectUrl&gt;
          &lt;!--
          &lt;d:ProjectSourceUrl m:null="true"&gt;&lt;/d:ProjectSourceUrl&gt;
          &lt;d:PackageSourceUrl m:null="true"&gt;&lt;/d:PackageSourceUrl&gt;
          &lt;d:DocsUrl m:null="true"&gt;&lt;/d:DocsUrl&gt;
          &lt;d:MailingListUrl m:null="true"&gt;&lt;/d:MailingListUrl&gt;
          &lt;d:BugTrackerUrl m:null="true"&gt;&lt;/d:BugTrackerUrl&gt;
          --&gt;
          &lt;d:ReportAbuseUrl&gt;http://gallery-host/package/ReportAbuse/&lt;xsl:value-of select="id"/&gt;/&lt;xsl:value-of select="version"/&gt;&lt;/d:ReportAbuseUrl&gt;
          &lt;d:ReleaseNotes&gt;&lt;xsl:value-of select="releaseNotes"/&gt;&lt;/d:ReleaseNotes&gt;
          &lt;!--
          &lt;d:PackageStatus&gt;&lt;/d:PackageStatus&gt;
          &lt;d:PackageSubmittedStatus m:null="true"&gt;&lt;/d:PackageSubmittedStatus&gt;
          &lt;d:RequireLicenseAcceptance m:type="Edm.Boolean"&gt;&lt;/d:RequireLicenseAcceptance&gt;
          --&gt;
          &lt;d:Tags xml:space="preserve"&gt;&lt;xsl:value-of select="tags"/&gt;&lt;/d:Tags&gt;
          &lt;d:Title&gt;&lt;xsl:value-of select="title"/&gt;&lt;/d:Title&gt;
          &lt;!--
          &lt;d:VersionDownloadCount m:type="Edm.Int32"&gt;&lt;/d:VersionDownloadCount&gt;
          --&gt;
        &lt;/m:properties&gt;
      &lt;/entry&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>This results in the output file containing no xml tags (the content is correctly included).</p>
  
  <p>How can I correct my transform.xsl to produce a single root <code>&lt;feed&gt;</code> element, with multiple child <code>&lt;entry&gt;</code> elements (so that my output is formatted like <a href="http://chocolatey.org/api/v2/Packages" rel="nofollow noreferrer">http://chocolatey.org/api/v2/Packages</a>)?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Thanks to the <a href="https://stackoverflow.com/a/31184442/68115">pointer</a> from @Martin Honnen, and <a href="https://stackoverflow.com/a/3954726/68115">another</a> from @Frédéric Hamidi (why is it always namespaces that kick you in the nethers, working with xml?), I got a little further with the transform:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" ?&gt;
  &lt;xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:output method="xml" indent="yes" omit-xml-declaration="yes" /&gt;
    &lt;xsl:template match="/"&gt;
      &lt;feed&gt;
        &lt;xsl:for-each select="p:package/p:metadata" xmlns:p="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"&gt;
          &lt;xsl:element name="entry"&gt;
            &lt;xsl:element name="id"&gt;&lt;xsl:value-of select="p:id"/&gt;&lt;/xsl:element&gt;
            &lt;xsl:element name="title"&gt;
              &lt;xsl:attribute name="type"&gt;text&lt;/xsl:attribute&gt;
              &lt;xsl:value-of select="p:title"/&gt;
            &lt;/xsl:element&gt;
            &lt;xsl:element name="summary"&gt;
              &lt;xsl:attribute name="type"&gt;text&lt;/xsl:attribute&gt;
              &lt;xsl:value-of select="p:summary"/&gt;&lt;/xsl:element&gt;
            &lt;xsl:element name="author"&gt;
              &lt;xsl:element name="name"&gt;&lt;xsl:value-of select="p:authors"/&gt;&lt;/xsl:element&gt;
            &lt;/xsl:element&gt;
            &lt;xsl:element name="link"&gt;
              &lt;xsl:attribute name="rel"&gt;edit-media&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="title"&gt;V2FeedPackage&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="href"&gt;Packages(Id='&lt;xsl:value-of select="p:id"/&gt;',Version='&lt;xsl:value-of select="p:version"/&gt;')/$value&lt;/xsl:attribute&gt;
            &lt;/xsl:element&gt;
            &lt;xsl:element name="link"&gt;
              &lt;xsl:attribute name="rel"&gt;edit&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="title"&gt;V2FeedPackage&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="href"&gt;Packages(Id='&lt;xsl:value-of select="p:id"/&gt;',Version='&lt;xsl:value-of select="p:version"/&gt;')&lt;/xsl:attribute&gt;
            &lt;/xsl:element&gt;
            &lt;xsl:element name="category"&gt;
              &lt;xsl:attribute name="term"&gt;NuGetGallery.V2FeedPackage&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="scheme"&gt;http://schemas.microsoft.com/ado/2007/08/dataservices/scheme&lt;/xsl:attribute&gt;
            &lt;/xsl:element&gt;
            &lt;xsl:element name="content"&gt;
              &lt;xsl:attribute name="type"&gt;application/zip&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="src"&gt;http://chocolatey.org/api/v2/package/&lt;xsl:value-of select="p:id"/&gt;/&lt;xsl:value-of select="p:version"/&gt;&lt;/xsl:attribute&gt;
            &lt;/xsl:element&gt;
          &lt;/xsl:element&gt;
          &lt;m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"&gt;
            &lt;d:Version&gt;&lt;xsl:value-of select="p:version"/&gt;&lt;/d:Version&gt;
            &lt;d:Copyright&gt;&lt;xsl:value-of select="p:copyright"/&gt;&lt;/d:Copyright&gt;
            &lt;!--
            &lt;d:Created m:type="Edm.DateTime"&gt;&lt;/d:Created&gt;
            &lt;d:Dependencies&gt;&lt;/d:Dependencies&gt;
            --&gt;
            &lt;d:Description&gt;&lt;xsl:value-of select="p:description"/&gt;&lt;/d:Description&gt;
            &lt;!--
            &lt;d:DownloadCount m:type="Edm.Int32"&gt;&lt;/d:DownloadCount&gt;
            --&gt;
            &lt;d:GalleryDetailsUrl&gt;http://gallery-host/packages/&lt;xsl:value-of select="p:id"/&gt;/&lt;xsl:value-of select="p:version"/&gt;&lt;/d:GalleryDetailsUrl&gt;
            &lt;d:IconUrl&gt;&lt;xsl:value-of select="p:iconUrl"/&gt;&lt;/d:IconUrl&gt;
            &lt;!--
            &lt;d:IsLatestVersion m:type="Edm.Boolean"&gt;&lt;/d:IsLatestVersion&gt;
            &lt;d:IsAbsoluteLatestVersion m:type="Edm.Boolean"&gt;&lt;/d:IsAbsoluteLatestVersion&gt;
            &lt;d:IsPrerelease m:type="Edm.Boolean"&gt;&lt;/d:IsPrerelease&gt;
            &lt;d:Language m:null="true"&gt;&lt;/d:Language&gt;
            &lt;d:Published m:type="Edm.DateTime"&gt;&lt;/d:Published&gt;
            --&gt;
            &lt;d:LicenseUrl&gt;&lt;xsl:value-of select="p:licenseUrl"/&gt;&lt;/d:LicenseUrl&gt;
            &lt;!--
            &lt;d:PackageHash&gt;&lt;/d:PackageHash&gt;
            &lt;d:PackageHashAlgorithm&gt;&lt;/d:PackageHashAlgorithm&gt;
            &lt;d:PackageSize m:type="Edm.Int64"&gt;&lt;/d:PackageSize&gt;
            --&gt;
            &lt;d:ProjectUrl&gt;&lt;xsl:value-of select="p:projectUrl"/&gt;&lt;/d:ProjectUrl&gt;
            &lt;!--
            &lt;d:ProjectSourceUrl m:null="true"&gt;&lt;/d:ProjectSourceUrl&gt;
            &lt;d:PackageSourceUrl m:null="true"&gt;&lt;/d:PackageSourceUrl&gt;
            &lt;d:DocsUrl m:null="true"&gt;&lt;/d:DocsUrl&gt;
            &lt;d:MailingListUrl m:null="true"&gt;&lt;/d:MailingListUrl&gt;
            &lt;d:BugTrackerUrl m:null="true"&gt;&lt;/d:BugTrackerUrl&gt;
            --&gt;
            &lt;d:ReportAbuseUrl&gt;http://gallery-host/package/ReportAbuse/&lt;xsl:value-of select="p:id"/&gt;/&lt;xsl:value-of select="p:version"/&gt;&lt;/d:ReportAbuseUrl&gt;
            &lt;d:ReleaseNotes&gt;&lt;xsl:value-of select="p:releaseNotes"/&gt;&lt;/d:ReleaseNotes&gt;
            &lt;!--
            &lt;d:PackageStatus&gt;&lt;/d:PackageStatus&gt;
            &lt;d:PackageSubmittedStatus m:null="true"&gt;&lt;/d:PackageSubmittedStatus&gt;
            &lt;d:RequireLicenseAcceptance m:type="Edm.Boolean"&gt;&lt;/d:RequireLicenseAcceptance&gt;
            --&gt;
            &lt;d:Tags xml:space="preserve"&gt;&lt;xsl:value-of select="p:tags"/&gt;&lt;/d:Tags&gt;
            &lt;d:Title&gt;&lt;xsl:value-of select="p:title"/&gt;&lt;/d:Title&gt;
            &lt;!--
            &lt;d:VersionDownloadCount m:type="Edm.Int32"&gt;&lt;/d:VersionDownloadCount&gt;
            --&gt;
          &lt;/m:properties&gt;
        &lt;/xsl:for-each&gt;
        &lt;xsl:for-each select="p:package/p:metadata" xmlns:p="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"&gt;
          &lt;xsl:element name="entry"&gt;
            &lt;xsl:element name="id"&gt;&lt;xsl:value-of select="p:id"/&gt;&lt;/xsl:element&gt;
            &lt;xsl:element name="title"&gt;
              &lt;xsl:attribute name="type"&gt;text&lt;/xsl:attribute&gt;
              &lt;xsl:value-of select="p:title"/&gt;
            &lt;/xsl:element&gt;
            &lt;xsl:element name="summary"&gt;
              &lt;xsl:attribute name="type"&gt;text&lt;/xsl:attribute&gt;
              &lt;xsl:value-of select="p:summary"/&gt;&lt;/xsl:element&gt;
            &lt;xsl:element name="author"&gt;
              &lt;xsl:element name="name"&gt;&lt;xsl:value-of select="p:authors"/&gt;&lt;/xsl:element&gt;
            &lt;/xsl:element&gt;
            &lt;xsl:element name="link"&gt;
              &lt;xsl:attribute name="rel"&gt;edit-media&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="title"&gt;V2FeedPackage&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="href"&gt;Packages(Id='&lt;xsl:value-of select="p:id"/&gt;',Version='&lt;xsl:value-of select="p:version"/&gt;')/$value&lt;/xsl:attribute&gt;
            &lt;/xsl:element&gt;
            &lt;xsl:element name="link"&gt;
              &lt;xsl:attribute name="rel"&gt;edit&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="title"&gt;V2FeedPackage&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="href"&gt;Packages(Id='&lt;xsl:value-of select="p:id"/&gt;',Version='&lt;xsl:value-of select="p:version"/&gt;')&lt;/xsl:attribute&gt;
            &lt;/xsl:element&gt;
            &lt;xsl:element name="category"&gt;
              &lt;xsl:attribute name="term"&gt;NuGetGallery.V2FeedPackage&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="scheme"&gt;http://schemas.microsoft.com/ado/2007/08/dataservices/scheme&lt;/xsl:attribute&gt;
            &lt;/xsl:element&gt;
            &lt;xsl:element name="content"&gt;
              &lt;xsl:attribute name="type"&gt;application/zip&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="src"&gt;http://chocolatey.org/api/v2/package/&lt;xsl:value-of select="p:id"/&gt;/&lt;xsl:value-of select="p:version"/&gt;&lt;/xsl:attribute&gt;
            &lt;/xsl:element&gt;
          &lt;/xsl:element&gt;
          &lt;m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"&gt;
            &lt;d:Version&gt;&lt;xsl:value-of select="p:version"/&gt;&lt;/d:Version&gt;
            &lt;d:Copyright&gt;&lt;xsl:value-of select="p:copyright"/&gt;&lt;/d:Copyright&gt;
            &lt;!--
            &lt;d:Created m:type="Edm.DateTime"&gt;&lt;/d:Created&gt;
            &lt;d:Dependencies&gt;&lt;/d:Dependencies&gt;
            --&gt;
            &lt;d:Description&gt;&lt;xsl:value-of select="p:description"/&gt;&lt;/d:Description&gt;
            &lt;!--
            &lt;d:DownloadCount m:type="Edm.Int32"&gt;&lt;/d:DownloadCount&gt;
            --&gt;
            &lt;d:GalleryDetailsUrl&gt;http://gallery-host/packages/&lt;xsl:value-of select="p:id"/&gt;/&lt;xsl:value-of select="p:version"/&gt;&lt;/d:GalleryDetailsUrl&gt;
            &lt;d:IconUrl&gt;&lt;xsl:value-of select="p:iconUrl"/&gt;&lt;/d:IconUrl&gt;
            &lt;!--
            &lt;d:IsLatestVersion m:type="Edm.Boolean"&gt;&lt;/d:IsLatestVersion&gt;
            &lt;d:IsAbsoluteLatestVersion m:type="Edm.Boolean"&gt;&lt;/d:IsAbsoluteLatestVersion&gt;
            &lt;d:IsPrerelease m:type="Edm.Boolean"&gt;&lt;/d:IsPrerelease&gt;
            &lt;d:Language m:null="true"&gt;&lt;/d:Language&gt;
            &lt;d:Published m:type="Edm.DateTime"&gt;&lt;/d:Published&gt;
            --&gt;
            &lt;d:LicenseUrl&gt;&lt;xsl:value-of select="p:licenseUrl"/&gt;&lt;/d:LicenseUrl&gt;
            &lt;!--
            &lt;d:PackageHash&gt;&lt;/d:PackageHash&gt;
            &lt;d:PackageHashAlgorithm&gt;&lt;/d:PackageHashAlgorithm&gt;
            &lt;d:PackageSize m:type="Edm.Int64"&gt;&lt;/d:PackageSize&gt;
            --&gt;
            &lt;d:ProjectUrl&gt;&lt;xsl:value-of select="p:projectUrl"/&gt;&lt;/d:ProjectUrl&gt;
            &lt;!--
            &lt;d:ProjectSourceUrl m:null="true"&gt;&lt;/d:ProjectSourceUrl&gt;
            &lt;d:PackageSourceUrl m:null="true"&gt;&lt;/d:PackageSourceUrl&gt;
            &lt;d:DocsUrl m:null="true"&gt;&lt;/d:DocsUrl&gt;
            &lt;d:MailingListUrl m:null="true"&gt;&lt;/d:MailingListUrl&gt;
            &lt;d:BugTrackerUrl m:null="true"&gt;&lt;/d:BugTrackerUrl&gt;
            --&gt;
            &lt;d:ReportAbuseUrl&gt;http://gallery-host/package/ReportAbuse/&lt;xsl:value-of select="p:id"/&gt;/&lt;xsl:value-of select="p:version"/&gt;&lt;/d:ReportAbuseUrl&gt;
            &lt;d:ReleaseNotes&gt;&lt;xsl:value-of select="p:releaseNotes"/&gt;&lt;/d:ReleaseNotes&gt;
            &lt;!--
            &lt;d:PackageStatus&gt;&lt;/d:PackageStatus&gt;
            &lt;d:PackageSubmittedStatus m:null="true"&gt;&lt;/d:PackageSubmittedStatus&gt;
            &lt;d:RequireLicenseAcceptance m:type="Edm.Boolean"&gt;&lt;/d:RequireLicenseAcceptance&gt;
            --&gt;
            &lt;d:Tags xml:space="preserve"&gt;&lt;xsl:value-of select="p:tags"/&gt;&lt;/d:Tags&gt;
            &lt;d:Title&gt;&lt;xsl:value-of select="p:title"/&gt;&lt;/d:Title&gt;
            &lt;!--
            &lt;d:VersionDownloadCount m:type="Edm.Int32"&gt;&lt;/d:VersionDownloadCount&gt;
            --&gt;
          &lt;/m:properties&gt;
        &lt;/xsl:for-each&gt;
      &lt;/feed&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>The output still contains too many <code>feed</code> elements, which I think is due to the way xsltproc handles wildcards/multiple input files (it's running a separate transform for each file, which is actually rather logical). If I could get rid of those, and find a nicer way of handling multiple input namespaces (rather than duplicating the transform code for each namespace), I'd be a happy bunny.</p>