merge two xml files using xslt

I would like to merge two xml files into one using xslt.

file1:

<cut> <content1> .... </content1> </cut>

file1:

<cut> <content2> .... </content2> </cut>

merged:
<cut>
<content1> ... </content1>
<content2> ... </content2>
</cut>

I would like to pass parameters to the xslt containing the files to merge.

xsltproc.exe" --stringparam file1 s:\file1.xml --stringparam file2 s:\file2.xml s:\merge.xslt

merge.xslt:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:exsl="http://exslt.org/common"
    extension-element-prefixes="exsl">

  <xsl:output indent="yes" omit-xml-declaration="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:param name="file1"/>
  <xsl:param name="file2"/>

  <xsl:variable name="big-doc-rtf">
    <xsl:copy-of select="document($file1)"/>
    <xsl:copy-of select="document($file2)"/>
  </xsl:variable>

  <xsl:variable name="big-doc" select="exsl:node-set($big-doc-rtf)"/>

  <xsl:template match="/">
    <cut>
      <xsl:apply-templates select="$big-doc/cut/*"/>
    </cut>
  </xsl:template>

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

  <xsl:template match="@*|text()|comment()|processing-instruction()">
    <xsl:copy-of select="."/>
  </xsl:template>

</xsl:stylesheet>

I only get an empty "cut" tag. What is wrong?

Answers


Can't repro the problem.

Most probably both document() functions in your code return "nothing" -- and this means that the URIs used as the 1st argument of each call don't identify a file (the file cannot be found/resolved), or the file doesn't contain a well-formed XML document.


not using xsltproc but xmllint:

(Edit: xsltproc also allows xinclude

--xinclude : do XInclude processing on document input

)

x1.xml

<cut><content1>content1</content1></cut>

x2.xml

<cut><content2>content2</content2></cut>

x3.xml

<?xml version="1.0"?>
<cut xmlns:xi="http://www.w3.org/2003/XInclude">
  <xi:include href="x1.xml" parse="xml" xpointer="xpointer(/cut/content1)"/>
  <xi:include href="x2.xml" parse="xml" xpointer="xpointer(/cut/content2)"/>
</cut>

run:

$ xmllint -xinclude  x3.xml 
<?xml version="1.0"?>
<cut xmlns:xi="http://www.w3.org/2003/XInclude">
  <content1>content1</content1>
  <content2>content2</content2>
</cut>

Need Your Help

SPOJ PRIME1 : TLE

c++ algorithm primes sieve-of-eratosthenes sieve

I tried implementing the segmented sieve algorithm for this [question]:http://www.spoj.pl/problems/PRIME1/ as follows :

git nested projects

git github nested git-submodules

I've a stable and functioning project X. I want a module to be added to it and that's is from some other project Y on github in my modules directory.