Note that there are some explanatory texts on larger screens.

plurals
  1. POTransform XML with XSLT in PHP
    primarykey
    data
    text
    <p>I'm trying to combine two xml-files and with a XSLT-file transform them into a XHTML-page. I have not done this before and can´t figure out how to do it. This is what I have so far, with just one xml-file:</p> <pre><code>&lt;?php $xsl = new DOMDocument(); $xsl-&gt;load("file.xsl"); $inputdom = new DomDocument(); $inputdom-&gt;load("file.xml"); $proc = new XSLTProcessor(); $xsl = $proc-&gt;importStylesheet($xsl); $proc-&gt;setParameter(null, "", ""); $newdom = $proc-&gt;transformToDoc($inputdom); print $newdom-&gt; saveXML(); </code></pre> <p>xsl-file with the :ss namespace. I'm not really sure how to use the ss prefix?</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"&gt; &lt;xsl:template match="/"&gt; &lt;html&gt; &lt;body&gt; &lt;table border="1"&gt; &lt;tr bgcolor="#9acd32"&gt; &lt;th&gt;Title&lt;/th&gt; &lt;th&gt;Title2&lt;/th&gt; &lt;/tr&gt; &lt;xsl:for-each select="something/some"&gt; &lt;tr&gt; &lt;td&gt;&lt;xsl:value-of select="title"/&gt;&lt;/td&gt; &lt;td&gt;&lt;xsl:value-of select="title2"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; </code></pre> <p></p> <p>xml-file</p> <pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt; &lt;?xml-stylesheet type="text/xsl" href="file.xsl"?&gt; &lt;something&gt; &lt;some&gt; &lt;Firstname&gt;Peter&lt;/Firstname&gt; &lt;Lastname&gt;Anderson&lt;/Lastname&gt; &lt;some&gt; ..... </code></pre> <p>If somebody could give me a kick in the right direction I would be grateful. </p> <p>Here is the second xml-file:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"&gt; &lt;DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"&gt; &lt;Created&gt;2012-09-25T13:44:01Z&lt;/Created&gt; &lt;/DocumentProperties&gt; &lt;OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office"&gt; &lt;AllowPNG/&gt; &lt;/OfficeDocumentSettings&gt; &lt;ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"&gt; &lt;WindowHeight&gt;14060&lt;/WindowHeight&gt; &lt;WindowWidth&gt;25040&lt;/WindowWidth&gt; &lt;WindowTopX&gt;25540&lt;/WindowTopX&gt; &lt;WindowTopY&gt;4100&lt;/WindowTopY&gt; &lt;Date1904/&gt; &lt;ProtectStructure&gt;False&lt;/ProtectStructure&gt; &lt;ProtectWindows&gt;False&lt;/ProtectWindows&gt; &lt;/ExcelWorkbook&gt; &lt;Styles&gt; &lt;Style ss:ID="Default" ss:Name="Normal"&gt; &lt;Alignment ss:Vertical="Bottom"/&gt; &lt;Borders/&gt; &lt;Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="12" ss:Color="#000000"/&gt; &lt;Interior/&gt; &lt;NumberFormat/&gt; &lt;Protection/&gt; &lt;/Style&gt; &lt;Style ss:ID="s62"&gt; &lt;Font ss:FontName="Courier" ss:Color="#000000"/&gt; &lt;/Style&gt; &lt;/Styles&gt; &lt;Worksheet ss:Name="Workbook1.csv"&gt; &lt;Table ss:ExpandedColumnCount="5" ss:ExpandedRowCount="79" x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="65" ss:DefaultRowHeight="15"&gt; &lt;Column ss:Index="2" ss:AutoFitWidth="0" ss:Width="43"/&gt; &lt;Column ss:AutoFitWidth="0" ss:Width="113"/&gt; &lt;Column ss:Index="5" ss:AutoFitWidth="0" ss:Width="220"/&gt; &lt;Row ss:Index="6"&gt; &lt;Cell ss:Index="3" ss:StyleID="s62"/&gt; &lt;/Row&gt; &lt;Row&gt; &lt;Cell ss:Index="3" ss:StyleID="s62"/&gt; &lt;/Row&gt; &lt;Row&gt; &lt;Cell ss:Index="3" ss:StyleID="s62"/&gt; &lt;/Row&gt; &lt;Row&gt; &lt;Cell ss:Index="2"&gt;&lt;Data ss:Type="String"&gt;id&lt;/Data&gt;&lt;/Cell&gt; &lt;Cell ss:StyleID="s62"&gt;&lt;Data ss:Type="String"&gt;latitude&lt;/Data&gt;&lt;/Cell&gt; &lt;Cell&gt;&lt;Data ss:Type="String"&gt;longitude&lt;/Data&gt;&lt;/Cell&gt; &lt;/Row&gt; &lt;Row&gt; &lt;Cell ss:Index="2"&gt;&lt;Data ss:Type="Number"&gt;8&lt;/Data&gt;&lt;/Cell&gt; &lt;Cell ss:StyleID="s62"&gt;&lt;Data ss:Type="Number"&gt;57.4999&lt;/Data&gt;&lt;/Cell&gt; &lt;Cell&gt;&lt;Data ss:Type="Number"&gt;15.8280&lt;/Data&gt;&lt;/Cell&gt; &lt;/Row&gt; ..... </code></pre> <p>So my question is how to combine data from both XML-files with the XSLT? I want the result to be the data in a table on a XHTML-page. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload