0

I trying to combine data from one XML-file and one Excel XML-file with XSLT. I can't get it to work and wonder if I can do it like this? I have not managed to get any output and could really use some help.

<?php

$xsl = new DOMDocument();
$xsl->load("file1.xsl");
$inputdom = new DomDocument();
$inputdom->load("file1.xml");

$proc = new XSLTProcessor();
$xsl = $proc->importStylesheet($xsl);
$proc->setParameter(null, "", "");

$newdom = $proc->transformToDoc($inputdom);
print $newdom-> saveXML();

.xsl

How to use the ss prefix?

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">

<xsl:variable name="file2" select="document('file2.xml')">
</xsl:variable>


<xsl:template match="/Test">
    <Test>
    <xsl:copy-of select="*" />
    <xsl:copy-of select="$file2/Test/*" />
    </Test>

</xsl:template>

</xsl:stylesheet>

1 Answer 1

0

It's a bit hard to say for sure without seeing the XML files in the question, but if the second file is Excel XML, then the root element will be Workbook but your XSLT is looking for a root of Test.

Try replacing this line....

<xsl:copy-of select="$file2/Test/*" />

With this line

<xsl:copy-of select="$file2/*" />

If you wanted to explicit refer to an element in your second file, using the ss namespace, you would do something like this

<xsl:copy-of select="$file2/ss:Workbook" />
Sign up to request clarification or add additional context in comments.

Comments

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.