xslt php select the first sibling and all its child nodes - php

How does one select the first sibling of a xml node with all its child nodes and apply some transformations on it? So far I only succeeded in selected either the first sibling and only the first sibling (no child nodes that is) or everything following the xml node.
Say we have xhtml like this:
<div class="chapter">Chapter <span class="number">1.1</span> Lorum ipsum</div>
<h2 class="article">Article <span class="number">1.</span> Lorum ipsum</h2>
<p>Lorum ipsum</p>
And the result we are after is xml like this:
<chapter>
<heading>
<label>Chapter</chapter>
<number>1.1</number>
<title>Lorum ipsum</title>
</heading>
<article>
<heading>
<label>Article</chapter>
<number>1.</number>
<title>Lorum ipsum</title>
</heading>
<par>Lorum ipsum</par>
</article>
</chapter>
My guess is that I need to do some regex magic to get the label and title tags right, but if this could also been done using plain xslt that would be great.

This XSLT 1.0 transformation:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xhtml"
>
<xsl:output encoding="utf-8" />
<!-- the identity template (copies all nodes verbatim, unless
more specific templates implement different behavior) -->
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*" />
</xsl:copy>
</xsl:template>
<!-- start by applying templates to all chapter divs -->
<xsl:template match="xhtml:html">
<text>
<xsl:apply-templates select="xhtml:body/xhtml:div[#class='chapter']" />
</text>
</xsl:template>
<!-- chapter div: generate heading, apply templates to adjacent h2 -->
<xsl:template match="xhtml:div[#class='chapter']">
<chapter>
<xsl:apply-templates select="." mode="heading" />
<!-- ... where the first preceding chapter div has the same ID -->
<xsl:apply-templates select="
following-sibling::xhtml:h2[
generate-id(preceding-sibling::xhtml:div[#class='chapter'][1])
=
generate-id(current())
]
"/>
</chapter>
</xsl:template>
<!-- h2: generate heading, apply templates to adjacent paras -->
<xsl:template match="xhtml:h2[#class='article']">
<article>
<xsl:apply-templates select="." mode="heading" />
<xsl:apply-templates select="
following-sibling::xhtml:p[
generate-id(preceding-sibling::xhtml:h2[#class='article'][1])
=
generate-id(current())
]
"/>
</article>
</xsl:template>
<!-- headings follow the same scheme, so we can use a unified template -->
<xsl:template match="xhtml:div | xhtml:h2" mode="heading">
<heading>
<label>
<xsl:value-of select="normalize-space(text()[1])" />
</label>
<number>
<xsl:value-of select="normalize-space(xhtml:span[#class='number'])" />
</number>
<title>
<xsl:value-of select="normalize-space(text()[2])" />
</title>
</heading>
</xsl:template>
<xsl:template match="xhtml:p">
<par>
<xsl:apply-templates select="node()" />
</par>
</xsl:template>
</xsl:stylesheet>
when applied to
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<div class="chapter">Chapter <span class="number">1.1</span> Lorum ipsum</div>
<h2 class="article">Article <span class="number">1.</span> Lorum ipsum</h2>
<p>Lorum ipsum A</p>
<p>Lorum ipsum B</p>
<h2 class="article">Article <span class="number">2.</span> Lorum ipsum</h2>
<p>Lorum ipsum D</p>
<h2 class="article">Article <span class="number">3.</span> Lorum ipsum</h2>
<p>Lorum ipsum E</p>
<p>Lorum ipsum F</p>
<div class="chapter">Chapter <span class="number">2.1</span> Lorum ipsum</div>
<h2 class="article">Article <span class="number">1.</span> Lorum ipsum</h2>
<p>Lorum ipsum G</p>
</body>
</html>
yields:
<text>
<chapter>
<heading>
<label>Chapter</label>
<number>1.1</number>
<title>Lorum ipsum</title>
</heading>
<article>
<heading>
<label>Article</label>
<number>1.</number>
<title>Lorum ipsum</title>
</heading>
<par>Lorum ipsum A</par>
<par>Lorum ipsum B</par>
</article>
<article>
<heading>
<label>Article</label>
<number>2.</number>
<title>Lorum ipsum</title>
</heading>
<par>Lorum ipsum D</par>
</article>
<article>
<heading>
<label>Article</label>
<number>3.</number>
<title>Lorum ipsum</title>
</heading>
<par>Lorum ipsum E</par>
<par>Lorum ipsum F</par>
</article>
</chapter>
<chapter>
<heading>
<label>Chapter</label>
<number>2.1</number>
<title>Lorum ipsum</title>
</heading>
<article>
<heading>
<label>Article</label>
<number>1.</number>
<title>Lorum ipsum</title>
</heading>
<par>Lorum ipsum G</par>
</article>
</chapter>
</text>

This stylesheet creates the desired output:
<xsl:template match="html:div[#class='chapter']" mode="chapter">
<xsl:element name="{#class}">
<heading>
<xsl:apply-templates mode="chapter" />
</heading>
<xsl:apply-templates select="following-sibling::html:h2[generate-id(preceding-sibling::html:div[#class='chapter'][1])=generate-id(current())]" mode="chapter" />
</xsl:element>
</xsl:template>
<!--template for h2 in "chapter" mode, creates article content for the chapter-->
<xsl:template match="html:h2[#class='article']" mode="chapter">
<xsl:element name="{#class}">
<heading>
<xsl:apply-templates mode="chapter"/>
</heading>
<xsl:apply-templates select="following-sibling::html:p[generate-id(preceding-sibling::html:h2[#class='article'][1])=generate-id(current())]" mode="chapter" />
</xsl:element>
</xsl:template>
<xsl:template match="text()[following-sibling::html:span[#class='number']]" mode="chapter">
<label><xsl:value-of select="normalize-space()"/></label>
</xsl:template>
<!--Generate an (number) element using the class attribute as the name of the element-->
<xsl:template match="html:span[#class='number']" mode="chapter">
<xsl:element name="{#class}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<!--title elements created for text nodes before the -->
<xsl:template match="text()[preceding-sibling::html:span[#class='number']]" mode="chapter">
<title><xsl:value-of select="normalize-space()"/></title>
</xsl:template>
<!--Template in "chapter" mode, creates a par element inside the article-->
<xsl:template match="html:p" mode="chapter">
<para><xsl:value-of select="normalize-space()"/></para>
</xsl:template>
<!--prevent text from bleeding through in output-->
<xsl:template match="text()" mode="chapter"/>
Using Tomalak's example input XML, produces:
<?xml version="1.0" encoding="UTF-8"?>
<book>
<chapter>
<heading>
<label>Chapter</label>
<number>1.1</number>
<title>Lorum ipsum</title>
</heading>
<article>
<heading>
<label>Article</label>
<number>1.</number>
<title>Lorum ipsum</title>
</heading>
<para>Lorum ipsum A</para>
<para>Lorum ipsum B</para>
</article>
<article>
<heading>
<label>Article</label>
<number>2.</number>
<title>Lorum ipsum</title>
</heading>
<para>Lorum ipsum D</para>
</article>
<article>
<heading>
<label>Article</label>
<number>3.</number>
<title>Lorum ipsum</title>
</heading>
<para>Lorum ipsum E</para>
<para>Lorum ipsum F</para>
</article>
</chapter>
<chapter>
<heading>
<label>Chapter</label>
<number>2.1</number>
<title>Lorum ipsum</title>
</heading>
<article>
<heading>
<label>Article</label>
<number>1.</number>
<title>Lorum ipsum</title>
</heading>
<para>Lorum ipsum G</para>
</article>
</chapter>
</book>

Related

how to build tree structure from xml [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 days ago.
This post was edited and submitted for review 7 days ago.
Improve this question
I have a small php script that read an xml file and build a tree structure list.
but i need it to build it another way.
each 'SO' is a group and some of them have an 'id' attribute and some og them have a 'PID' with a value
i want the tree to be build on this, if the 'PID' value matches a 'SO' id attribute then the SO must be a brench of that 'SO'.
xml example:
<?xml version="1.0" encoding="utf-8"?>
<Database Id="fb05">
<Header>
<RegionId>1000</RegionId>
<ChildRegionId>2</ChildRegionId>
<FileCreator>PC</FileCreator>
<AssemblyVersion>1.19.0.8076</AssemblyVersion>
<FileOwner>kodak</FileOwner>
<DatabaseVersion>-1--1</DatabaseVersion>
<LastUsedDatabaseVersion>-1--1</LastUsedDatabaseVersion>
<LastSavedDate>07.02.2023 17:45:32</LastSavedDate>
</Header>
<Data>
<SO Id="P8736ae982b4f40aca2d6d9e64f989f59">
<OID>0</OID>
<N>Node</N>
<PID>-1</PID>
<Ms />
</SO>
<SO Id="P63d414fdaf8c414ab2bcc82314e94eb1">
<N>45.1</N>
<PID>P8736ae982b4f40aca2d6d9e64f989f59</PID>
<OID>1</OID>
<Ms />
<Ps>
<P Id="65">
<V>45.1</V>
</P>
</Ps>
</SO>
<SO Id="P1aab4a4b96664cd5a8c579b85b55c775">
<OID>2</OID>
<N>Tavle Navn 1</N>
<PID>P63d414fdaf8c414ab2bcc82314e94eb1</PID>
<Ps>
<P Id="71">
<V>Tavle Navn 1</V>
</P>
<P Id="3">
<V>TN-S</V>
</P>
<P Id="72">
<V>Isolationtest BMS-KT.45.6A.-1.01</V>
</P>
</Ps>
<Ms>
<M Id="P7bd80659b03c44d4887695db676157a0">
<MID>4</MID>
<IGuIds>
<IGuId>21101825-20.04.2021-2.13.26-4.0-ALAM</IGuId>
</IGuIds>
<MPs>
<MP Id="1">
<V>07.01.2022 09:30:31</V>
</MP>
<MP Id="2">
<V>ALAM</V>
</MP>
<MP Id="3">
<V>2.13.26</V>
</MP>
<MP Id="4">
<V>500 V</V>
</MP>
<MP Id="11">
<V>-</V>
</MP>
</MPs>
<Ls>
<L Id="1">
<V>1 MOhm</V>
</L>
</Ls>
<Rs>
<R Id="9">
<V>>999MOhm</V>
<S>1</S>
</R>
<R Id="10">
<V>525V</V>
<S>0</S>
</R>
</Rs>
<S>1</S>
</M>
</Ms>
</SO>
<SO Id="Pdef14a1c6ecb490795743ed9c7a5c6bb">
<OID>9</OID>
<N>F1</N>
<PID>P1aab4a4b96664cd5a8c579b85b55c775</PID>
<Ps>
<P Id="96">
<V>F1</V>
</P>
<P Id="109">
<V>IEC/EN</V>
</P>
<P Id="111">
<V>100 A</V>
</P>
<P Id="110">
<V>10 A</V>
</P>
<P Id="105">
<V>0.4 s</V>
</P>
<P Id="108">
<V>C</V>
</P>
<P Id="114">
<V>30 mA</V>
</P>
<P Id="113">
<V>A</V>
</P>
<P Id="95">
<V>Kredsløb nr</V>
</P>
<P Id="97">
<V>Beskrivelse af kreds sikring</V>
</P>
<P Id="98">
<V>Kreds lokation</V>
</P>
<P Id="625" />
<P Id="103" />
<P Id="102" />
<P Id="100" />
<P Id="99" />
</Ps>
<Ms>
<M Id="Pe1c73a71b6f8426794f3a9755fc43001">
<MID>7</MID>
<IGuIds>
<IGuId>21101825-20.04.2021-2.13.26-4.0-ALAM</IGuId>
</IGuIds>
<MPs>
<MP Id="1">
<V>07.01.2022 09:41:28</V>
</MP>
<MP Id="2">
<V>ALAM</V>
</MP>
<MP Id="3">
<V>2.13.26</V>
</MP>
<MP Id="56">
<V>LPE</V>
</MP>
<MP Id="152">
<V>Rpe</V>
</MP>
<MP Id="338">
<V>standard</V>
</MP>
</MPs>
<Ls>
<L Id="3">
<V>2 Ohm</V>
</L>
</Ls>
<Rs>
<R Id="21">
<V>0.02Ohm</V>
<S>1</S>
</R>
<R Id="22">
<V>0.0Ohm</V>
<S>0</S>
</R>
<R Id="23">
<V>0.0Ohm</V>
<S>0</S>
</R>
<R Id="26">
<V>Yes</V>
<S>0</S>
</R>
</Rs>
<S>1</S>
</M>
<M Id="P6528dcb9c4c04ba68e508bf3fdd172cc">
<MID>14</MID>
<IGuIds>
<IGuId>21101825-20.04.2021-2.13.26-4.0-ALAM</IGuId>
</IGuIds>
<MPs>
<MP Id="1">
<V>07.01.2022 09:37:27</V>
</MP>
<MP Id="2">
<V>ALAM</V>
</MP>
<MP Id="3">
<V>2.13.26</V>
</MP>
<MP Id="131">
<V>fixed</V>
</MP>
<MP Id="20">
<V>AC</V>
</MP>
<MP Id="15">
<V>30 mA</V>
</MP>
<MP Id="233">
<V>-</V>
</MP>
<MP Id="14">
<V>EN 61008 / EN 61009</V>
</MP>
<MP Id="242">
<V>TN/TT</V>
</MP>
<MP Id="17">
<V>G</V>
</MP>
</MPs>
<Ls>
<L Id="6">
<V>50 V</V>
</L>
</Ls>
<Rs>
<R Id="116">
<V>24.6ms</V>
<S>0</S>
</R>
<R Id="117">
<V>33.4ms</V>
<S>0</S>
</R>
<R Id="120">
<V>6.0ms</V>
<S>0</S>
</R>
<R Id="121">
<V>11.8ms</V>
<S>0</S>
</R>
<R Id="122">
<V>>300ms</V>
<S>0</S>
</R>
<R Id="123">
<V>>300ms</V>
<S>0</S>
</R>
<R Id="124">
<V>22.5mA</V>
<S>0</S>
</R>
<R Id="125">
<V>24.0mA</V>
<S>0</S>
</R>
<R Id="114">
<V>0.1V</V>
<S>0</S>
</R>
</Rs>
<S>1</S>
</M>
<M Id="Pe931d0d28236473c98d6917e772dd95a">
<MID>14</MID>
<IGuIds>
<IGuId>21101825-20.04.2021-2.13.26-4.0-ALAM</IGuId>
</IGuIds>
<MPs>
<MP Id="1">
<V>07.01.2022 09:39:00</V>
</MP>
<MP Id="2">
<V>ALAM</V>
</MP>
<MP Id="3">
<V>2.13.26</V>
</MP>
<MP Id="131">
<V>fixed</V>
</MP>
<MP Id="20">
<V>A</V>
</MP>
<MP Id="15">
<V>30 mA</V>
</MP>
<MP Id="233">
<V>-</V>
</MP>
<MP Id="14">
<V>EN 61008 / EN 61009</V>
</MP>
<MP Id="242">
<V>TN/TT</V>
</MP>
<MP Id="17">
<V>G</V>
</MP>
</MPs>
<Ls>
<L Id="6">
<V>50 V</V>
</L>
</Ls>
<Rs>
<R Id="116">
<V>27.6ms</V>
<S>0</S>
</R>
<R Id="117">
<V>13.4ms</V>
<S>0</S>
</R>
<R Id="120">
<V>5.1ms</V>
<S>0</S>
</R>
<R Id="121">
<V>11.2ms</V>
<S>0</S>
</R>
<R Id="122">
<V>>300ms</V>
<S>0</S>
</R>
<R Id="123">
<V>>300ms</V>
<S>0</S>
</R>
<R Id="124">
<V>39.0mA</V>
<S>0</S>
</R>
<R Id="125">
<V>27.0mA</V>
<S>0</S>
</R>
<R Id="114">
<V>0.0V</V>
<S>0</S>
</R>
</Rs>
<S>1</S>
</M>
<M Id="Pe95c037ce6054bf29f593c7b51450eca">
<MID>2</MID>
<IGuIds>
<IGuId>21101825-20.04.2021-2.13.26-4.0-ALAM</IGuId>
</IGuIds>
<MPs>
<MP Id="1">
<V>07.01.2022 09:42:09</V>
</MP>
<MP Id="2">
<V>ALAM</V>
</MP>
<MP Id="3">
<V>2.13.26</V>
</MP>
<MP Id="230">
<V>1-phase</V>
</MP>
<MP Id="434">
<V>-</V>
</MP>
<MP Id="231">
<V>Voltage</V>
</MP>
<MP Id="242">
<V>TN/TT</V>
</MP>
<MP Id="436">
<V>Off</V>
</MP>
</MPs>
<Ls>
<L Id="97">
<V>207 V</V>
</L>
<L Id="98">
<V>253 V</V>
</L>
<L Id="101">
<V>207 V</V>
</L>
<L Id="102">
<V>253 V</V>
</L>
<L Id="103">
<V>0 V</V>
</L>
<L Id="104">
<V>10 V</V>
</L>
</Ls>
<Rs>
<R Id="1">
<V>237V</V>
<S>0</S>
</R>
<R Id="2">
<V>237V</V>
<S>0</S>
</R>
<R Id="3">
<V>0V</V>
<S>0</S>
</R>
<R Id="4">
<V>50.0Hz</V>
<S>0</S>
</R>
</Rs>
<S>1</S>
</M>
<M Id="Pd9ea820cde7b4e18935e493578d30c33">
<MID>17</MID>
<IGuIds>
<IGuId>21101825-20.04.2021-2.13.26-4.0-ALAM</IGuId>
</IGuIds>
<MPs>
<MP Id="1">
<V>07.01.2022 09:42:54</V>
</MP>
<MP Id="2">
<V>ALAM</V>
</MP>
<MP Id="3">
<V>2.13.26</V>
</MP>
<MP Id="108">
<V>C</V>
</MP>
<MP Id="28">
<V>10 A</V>
</MP>
<MP Id="29">
<V>0.1 s</V>
</MP>
<MP Id="31">
<V>1</V>
</MP>
<MP Id="235">
<V>-</V>
</MP>
<MP Id="242">
<V>TN/TT</V>
</MP>
</MPs>
<Ls>
<L Id="13">
<V>100 A</V>
</L>
</Ls>
<Rs>
<R Id="34">
<V>3.72kA</V>
<S>1</S>
</R>
<R Id="205">
<V>0.06Ohm</V>
<S>0</S>
</R>
<R Id="37">
<V>0.03Ohm</V>
<S>0</S>
</R>
<R Id="38">
<V>0.06Ohm</V>
<S>0</S>
</R>
<R Id="39">
<V>237V</V>
<S>0</S>
</R>
</Rs>
<S>1</S>
</M>
</Ms>
</SO>
<SO Id="Pf39c7fa412374063942a750fb782aca5">
<OID>2</OID>
<N>Tavle Navn 2</N>
<PID>P63d414fdaf8c414ab2bcc82314e94eb1</PID>
<Ps>
<P Id="71">
<V>Tavle Navn 2</V>
</P>
<P Id="3">
<V>TN-S</V>
</P>
<P Id="72">
<V>Isolationtest BMS-KT.45.6A.-1.01</V>
</P>
</Ps>
<Ms>
<M Id="P33b5ba5a01de477894b5ec64bba861e5">
<MID>4</MID>
<IGuIds />
<MPs>
<MP Id="1">
<V>07.01.2022 09:30:31</V>
</MP>
<MP Id="2">
<V>ALAM</V>
</MP>
<MP Id="3">
<V>2.13.26</V>
</MP>
<MP Id="4">
<V>500 V</V>
</MP>
<MP Id="11">
<V>-</V>
</MP>
</MPs>
<Ls>
<L Id="1">
<V>1 MOhm</V>
</L>
</Ls>
<Rs />
<S>5</S>
</M>
</Ms>
</SO>
<SO Id="Pa223cb2e6b864204a698c4bbf5c397a5">
<OID>9</OID>
<N>F1</N>
<PID>Pf39c7fa412374063942a750fb782aca5</PID>
<Ps>
<P Id="96">
<V>F1</V>
</P>
<P Id="109">
<V>IEC/EN</V>
</P>
<P Id="111">
<V>100 A</V>
</P>
<P Id="110">
<V>10 A</V>
</P>
<P Id="105">
<V>0.4 s</V>
</P>
<P Id="108">
<V>C</V>
</P>
<P Id="114">
<V>30 mA</V>
</P>
<P Id="113">
<V>A</V>
</P>
<P Id="95">
<V>Kredsløb nr</V>
</P>
<P Id="97">
<V>Beskrivelse af kreds sikring</V>
</P>
<P Id="98">
<V>Kreds lokation</V>
</P>
</Ps>
<Ms>
<M Id="P887aca482c74455d8ba836d8aa2227d7">
<MID>7</MID>
<IGuIds />
<MPs>
<MP Id="1">
<V>07.01.2022 09:41:28</V>
</MP>
<MP Id="2">
<V>ALAM</V>
</MP>
<MP Id="3">
<V>2.13.26</V>
</MP>
<MP Id="56">
<V>LPE</V>
</MP>
<MP Id="152">
<V>Rpe</V>
</MP>
<MP Id="338">
<V>standard</V>
</MP>
</MPs>
<Ls>
<L Id="3">
<V>2 Ohm</V>
</L>
</Ls>
<Rs />
<S>5</S>
</M>
<M Id="P6b617c0c7f174edd9f6e6ba5d109a227">
<MID>14</MID>
<IGuIds />
<MPs>
<MP Id="1">
<V>07.01.2022 09:37:27</V>
</MP>
<MP Id="2">
<V>ALAM</V>
</MP>
<MP Id="3">
<V>2.13.26</V>
</MP>
<MP Id="131">
<V>fixed</V>
</MP>
<MP Id="20">
<V>AC</V>
</MP>
<MP Id="15">
<V>30 mA</V>
</MP>
<MP Id="233">
<V>-</V>
</MP>
<MP Id="14">
<V>EN 61008 / EN 61009</V>
</MP>
<MP Id="242">
<V>TN/TT</V>
</MP>
<MP Id="17">
<V>G</V>
</MP>
</MPs>
<Ls>
<L Id="6">
<V>50 V</V>
</L>
</Ls>
<Rs />
<S>5</S>
</M>
<M Id="Pa85b10feaabb44c89de77669c1723762">
<MID>14</MID>
<IGuIds />
<MPs>
<MP Id="1">
<V>07.01.2022 09:39:00</V>
</MP>
<MP Id="2">
<V>ALAM</V>
</MP>
<MP Id="3">
<V>2.13.26</V>
</MP>
<MP Id="131">
<V>fixed</V>
</MP>
<MP Id="20">
<V>A</V>
</MP>
<MP Id="15">
<V>30 mA</V>
</MP>
<MP Id="233">
<V>-</V>
</MP>
<MP Id="14">
<V>EN 61008 / EN 61009</V>
</MP>
<MP Id="242">
<V>TN/TT</V>
</MP>
<MP Id="17">
<V>G</V>
</MP>
</MPs>
<Ls>
<L Id="6">
<V>50 V</V>
</L>
</Ls>
<Rs />
<S>5</S>
</M>
<M Id="P65d2c18f53a84fd9a20e282849821a90">
<MID>2</MID>
<IGuIds />
<MPs>
<MP Id="1">
<V>07.01.2022 09:42:09</V>
</MP>
<MP Id="2">
<V>ALAM</V>
</MP>
<MP Id="3">
<V>2.13.26</V>
</MP>
<MP Id="230">
<V>1-phase</V>
</MP>
<MP Id="434">
<V>-</V>
</MP>
<MP Id="231">
<V>Voltage</V>
</MP>
<MP Id="242">
<V>TN/TT</V>
</MP>
<MP Id="436">
<V>Off</V>
</MP>
</MPs>
<Ls>
<L Id="97">
<V>207 V</V>
</L>
<L Id="98">
<V>253 V</V>
</L>
<L Id="101">
<V>207 V</V>
</L>
<L Id="102">
<V>253 V</V>
</L>
<L Id="103">
<V>0 V</V>
</L>
<L Id="104">
<V>10 V</V>
</L>
</Ls>
<Rs />
<S>5</S>
</M>
<M Id="Paf889a4c35e74ae79023232f78b0d24f">
<MID>17</MID>
<IGuIds />
<MPs>
<MP Id="1">
<V>07.01.2022 09:42:54</V>
</MP>
<MP Id="2">
<V>ALAM</V>
</MP>
<MP Id="3">
<V>2.13.26</V>
</MP>
<MP Id="108">
<V>C</V>
</MP>
<MP Id="28">
<V>10 A</V>
</MP>
<MP Id="29">
<V>0.1 s</V>
</MP>
<MP Id="31">
<V>1</V>
</MP>
<MP Id="235">
<V>-</V>
</MP>
<MP Id="242">
<V>TN/TT</V>
</MP>
</MPs>
<Ls>
<L Id="13">
<V>100 A</V>
</L>
</Ls>
<Rs />
<S>5</S>
</M>
</Ms>
</SO>
</Data>
<Is>
<I>
<IGuId>21101825-20.04.2021-2.13.26-4.0-ALAM</IGuId>
<IHwV>4.0</IHwV>
<IMiNm>MI 3152</IMiNm>
<ISwV>2.13.26</ISwV>
<ISer>21101825</ISer>
<ICalD>20.04.2021</ICalD>
<IPCode>ALAM</IPCode>
</I>
<I>
<IGuId>21101825-20.04.2021-2.13.42-4.0-ALAM</IGuId>
<IHwV>4.0</IHwV>
<INm>EurotestXC</INm>
<IMiNm>MI 3152</IMiNm>
<ISwV>2.13.42</ISwV>
<ISer>21101825</ISer>
<ICalD>20.04.2021</ICalD>
<IPCode>ALAM</IPCode>
</I>
</Is>
<Us>
<U />
</Us>
</Database>
foreach ($xml->Data->SO as $SO) {
if($SO->OID) {
echo '<li class="'.$IODs[(string)$SO->OID].'" alt="' . $SO->OID . ' title="' . $SO->OID . '">'. $SO->N . '';
echo '<ul>';
} else {
echo "OID: " . $SO->OID . "<br>";
echo "N: " . $SO->N . "<br>";
}
foreach ($SO->Ms->M as $M) {
echo '<li class="'.($M->S == 1 ? 'test_true' : 'test_false').'" alt="' . $M->S . ' title="' . $M->S . '">'. $MIDs[(string)$M->MID] . '';
}
if ($SO->As) {
foreach ($SO->As->A as $A) {
echo "<br>A: " . $A . "<br>";
}
}
}

How to find HTML element using file_get_html

using library simple_html_dom.php
$html = file_get_html($link);
In structure like this
<div class="ps">
<h3>Lorem ipsum 1</h3>
<p>Lorem ipsum 2</p>
<h3>Lorem ipsum 3</h3>
<p>Lorem ipsum 4</p>
<div class="extras250">
<div class="boxType3 naSkroty">
<div class="boxBody shortList">
<h3>Lorem ipsum 5</h3>
</div>
</div>
<div class="boxType4 wsparcie">
<div class="boxBody">
<h3>Lorem ipsum 6</h3>
<p>Lorem ipsum 7</p>
</div>
</div>
</div>
</div>
foreach ($html->find('.ps h3') as $naglowek) {
$info['naglowek'][$i] = $naglowek->plaintext;
$i++;
}
I'd like to find <h3> but only first level (not nested) but foreach finding all of them. How to do this ? I tried
foreach ($html->find('.ps > h3') as $naglowek)
but not works.
not sure but check once
foreach ($html->find('.ps > h3:first') as $naglowek)

Fatal error:call to member function fetch_array?

I am trying to create a login form, in that login form I am using fetch_array() method to fetch the fields that user enter,but it showing some errors:
Login.php
<?php
include ("Connection.php");
?>
<?php
if(isset($_POST['Login']))
{
$Em = $_POST['form-email'];
$Pw = $_POST['form-password'];
$result = $con->query("SELECT * FROM userdetails where Email='$Em' Password='$Pw'");
$row = $result->fetch_assoc(MYSQLI_BOTH);
session_start();
$_SESSION["UserID"] = $row['UserID'];
header('Location: index.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>GTEC Registration Form Template</title>
<!-- CSS -->
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:400,100,300,500">
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="assets/css/form-elements.css">
<link rel="stylesheet" href="assets/css/style.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Favicon and touch icons -->
</head>
<body>
<!-- Top content -->
<div class="top-content">
<div class="inner-bg">
<div class="container">
<div class="row">
<div class="col-sm-7 text">
<h1><strong>GTEC Network</strong> Registration Form</h1>
<div class="description">
<p class="jumbotron">
To be a premier Institution of choice in the region and become one of the leading educational Institutions in the country widely recognized for providing high quality, transformative and affordable value based education in the field of Engineering and Technology.
</p>
</div>
<div class="top-big-link">
<a class="btn btn-link-2" href="registrer.php">Sign Up!</a>
</div>
</div>
<div class="col-sm-5 form-box">
<div class="form-top">
<div class="form-top-left">
<h3>Login</h3>
<p>Fill in the form below to get instant access:<br/>
Once you login your account ,<br/>
You can access gtec network thereby you can view ur syllabus,timetable,updates,
internal marks,results,also you can ur forum for many purpose</p>
</div>
<div class="form-top-right">
<i class="fa fa-pencil"></i>
</div>
</div>
<div class="form-bottom">
<form role="form" action="" method="post" class="Login-form">
<div class="form-group">
<label class="sr-only" for="form-email">Email</label>
<input type="email" name="form-email" placeholder="Email..." class="form-email form-control" id="form-email">
</div>
<div class="form-group">
<label class="sr-only" for="form-password">Email</label>
<input type="password" name="form-password" placeholder="Password..." class="form-password form-control" id="form-password">
</div>
<button type="submit" class="btn" name="Login">Login!</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Javascript -->
<script src="assets/js/jquery-1.11.1.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/jquery.backstretch.min.js"></script>
<script src="assets/js/retina-1.1.0.min.js"></script>
<script src="assets/js/scripts.js"></script>
<!--[if lt IE 10]>
<script src="assets/js/placeholder.js"></script>
<![endif]-->
</body>
</html>
index.php
<?php session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>GTEC NetWork</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/business-frontpage.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<?php echo $_SESSION['UserID'];?>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">GTEC NetWork</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
About
</li>
<li>
Services
</li>
<li>
Contact
</li>
<li>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Image Background Page Header -->
<!-- Note: The background image is set within the business-casual.css file. -->
<header class="business-header">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1 class="tagline">GTEC Student Info System</h1>
</div>
</div>
</div>
</header>
<!-- Page Content -->
<div class="container">
<hr>
<div class="row">
<div class="col-sm-8">
<h2>What We Do</h2>
<p>Introduce the visitor to the business using clear, informative text. Use well-targeted keywords within your sentences to make sure search engines can find the business.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Et molestiae similique eligendi reiciendis sunt distinctio odit? Quia, neque, ipsa, adipisci quisquam ullam deserunt accusantium illo iste exercitationem nemo voluptates asperiores.</p>
<p>
<a class="btn btn-default btn-lg" href="#">Call to Action »</a>
</p>
</div>
<div class="col-sm-4">
<h2>Contact Us</h2>
<address>
<strong>Start Bootstrap</strong>
<br>3481 Melrose Place
<br>Beverly Hills, CA 90210
<br>
</address>
<address>
<abbr title="Phone">P:</abbr>(123) 456-7890
<br>
<abbr title="Email">E:</abbr> name#example.com
</address>
</div>
</div>
<!-- /.row -->
<hr>
<div class="row">
<div class="col-sm-4">
<img class="img-circle img-responsive img-center" src="http://placehold.it/300x300" alt="">
<h2>Marketing Box #1</h2>
<p>These marketing boxes are a great place to put some information. These can contain summaries of what the company does, promotional information, or anything else that is relevant to the company. These will usually be below-the-fold.</p>
</div>
<div class="col-sm-4">
<img class="img-circle img-responsive img-center" src="http://placehold.it/300x300" alt="">
<h2>Marketing Box #2</h2>
<p>The images are set to be circular and responsive. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.</p>
</div>
<div class="col-sm-4">
<img class="img-circle img-responsive img-center" src="http://placehold.it/300x300" alt="">
<h2>Marketing Box #3</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.</p>
</div>
</div>
<!-- /.row -->
<hr>
</div>
<!-- /.container -->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
This is login form and index.php, I already created register form it working perfectly, the data that I registered is stored correctly, but the problem is in login form, it is redirection to index page, and the error is:
Fatal error: Call to a member function fetch_assoc() on a non-object in C:\xampp\htdocs\Studentmanagementsys\Login.php on line 13
You have syntax error in your sql query. When you executing query by mysqli, if there some sql syntax errors, method $con->query(...) will return boolean false. So, you have false value in your $result.
Php cant call method on boolean value: $result->fetch_assoc(), cause boolean is scalar value, not object. (sorry for my english)

How to convert an html template to joomla

I am new to joomla and trying to change a simple html template to joomla template. I made changes over the templatedetails.xml and index.php. Now my template is visible at templates of joomla. But it is not allowing to add menus or perform any joomla operation over to it.
Here is my index.php file,
<?php
/****************************************************
#####################################################
##-------------------------------------------------##
## TEMP ##
##-------------------------------------------------##
## Copyright = TEMP - 2013 ##
## Date = april 2013 ##
## Author = XYZ ##
## Websites = http://www.google.com ##
## ##
#####################################################
****************************************************/
// no direct access
defined('_JEXEC') or die('Restricted access');
/* The following line loads the MooTools JavaScript Library */
JHtml::_('behavior.framework', true);
/* The following line gets the application object for things like displaying the site name */
$app = JFactory::getApplication();
$csite_name = $app->getCfg('sitename');
$path = $this->baseurl.'/templates/'.$this->template;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<jdoc:include type="head" />
<?php $mod_right = $this->countModules( 'position-7' );
if ( $mod_right ) {
$width = '';
} else {
$width = '-full'; }
?>
<?php
$newsflash = $this->params->get("newsflash", " Content to be added here.. ");
?>
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/template.css" type="text/css" />
<script language="javascript" type="text/javascript" src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template?>/js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template?>/js/superfish.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template?>/js/hoverIntent.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template?>/js/hide.js"></script>
<script type="text/javascript" src="templates/<?php echo $this->template ?>/js/slideshow.js"></script>
<link rel="icon" type="image/gif" href="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template; ?>/favicon.gif" />
<!--[if IE 7]>
<link href="templates/<?php echo $this->template ?>/css/ie7.css" rel="stylesheet" type="text/css" />
<![endif]-->
<script type="text/javascript">
// initialise plugins
jQuery(function(){
jQuery('.navigation ul').superfish();
});
</script>
</head>
<body>
<!-- start header -->
<div id="header">
<div id="logo">
</div>
<div id="menu">
<ul id="main">
<li class="current_page_item">Home</li>
<li>Courses and Admission </li>
<li>Department</li>
<li>Research</li>
<li>Hospital</li>
</ul>
<ul id="feed">
<li>Webmail</li>
<li>Contact us </li>
</ul>
</div>
</div>
<!-- end header -->
<div id="wrapper">
<!-- start page -->
<div id="page">
<div id="sidebar1" class="sidebar">
<ul>
<li>
<h2>Recent Posts</h2>
<marquee scrollamount="3" direction="up" onmouseout="start()" onmouseover="stop();">
<ul>
<li>Aliquam libero</li>
<li>Consectetuer adipiscing elit</li>
<li>Metus aliquam pellentesque</li>
<li>Suspendisse iaculis mauris</li>
<li>Proin gravida orci porttitor</li>
<li>Aliquam libero</li>
<li>Consectetuer adipiscing elit</li>
<li>Metus aliquam pellentesque</li>
<li>Suspendisse iaculis mauris</li>
<li>Proin gravida orci porttitor</li>
</ul>
</marquee>
</li>
<li>
<h2>Recent Comments</h2>
<ul>
<li> Templates on Aliquam libero</li>
<li> Templates on Consectetuer adipiscing elit</li>
<li> Templates on Metus aliquam pellentesque</li>
<li> Templates on Suspendisse iaculis mauris</li>
<li> Templates on Urnanet non molestie semper</li>
<li> Templates on Proin gravida orci porttitor</li>
</ul>
</li>
<li>
<h2>Categories</h2>
<ul>
<li>Aliquam libero</li>
<li>Consectetuer adipiscing elit</li>
<li>Metus aliquam pellentesque</li>
<li>Suspendisse iaculis mauris</li>
<li>Urnanet non molestie semper</li>
<li>Proin gravida orci porttitor</li>
</ul>
</li>
<li>
<h2>Archives</h2>
<ul>
<li>September (23)</li>
<li>August (31)</li>
<li>July (31)</li>
<li>June (30)</li>
<li>May (31)</li>
</ul>
</li>
</ul>
</div>
<!-- start content -->
<div id="content">
<div class="flower">
<img src="templates/<?php echo $this->template ?>/images/img06.jpg" width="510" height="250" alt="logotype" /></div>
<div class="post">
<h1 class="title">Welcome to TEMP !</h1>
<div class="entry">
<p>
<strong>TEMP </strong> is one of the SIX TEMP like apex healthcare institutes being established by the Ministry of Health & Family Welfare, Government of India under the Pradhan Mantri Swasthya Suraksha Yojna (PMSSY). With the aim of correcting regional imbalances in quality tertiary level healthcare in the country, and attaining self sufficiency in graduate and postgraduate medical education and training the PMSSY planned to set up 6 new TEMP like institutions in under served areas of the country.</p>
<p>These institutions are being established by an Act of Parliament on the lines of the original All India Institute of Medical Sciences in New Delhi which imparts both undergraduate and postgraduate medical education in all its branches and related fields, along with nursing and paramedical training. to bring together in one place educational facilities of the highest order for the training of personnel in all branches of health care activity. </p>
<p> </p>
<p class="links">«« Read More »»</p>
</div>
</div>
<div class="post">
<h2 class="title">Sample Tags</h2>
<div class="entry">
<h3>An H3 Followed by a Blockquote:</h3>
<blockquote>
<p>“Donec leo, vivamus nibh in augue at urna congue rutrum. Quisque dictum integer nisl risus, sagittis convallis, rutrum id, congue, and nibh.”</p>
</blockquote>
<h3>Bulleted List:</h3>
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Phasellus nec erat sit amet nibh pellentesque congue.</li>
<li>Cras vitae metus aliquam risus pellentesque pharetra.</li>
</ul>
<h3>Numbered List:</h3>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Phasellus nec erat sit amet nibh pellentesque congue.</li>
<li>Cras vitae metus aliquam risus pellentesque pharetra.</li>
</ol>
<p class="links">«« Read More »»</p>
</div>
</div>
<!-- end content -->
<!-- start sidebars -->
<div id="sidebar2" class="sidebar">
<ul>
<li>
<form id="searchform" method="get" action="#">
<div>
<h2>Site Search</h2>
<input type="text" name="s" id="s" size="15" value="" />
</div>
</form>
</li>
<li>
<h2>Tags</h2>
<p class="tag">dolor ipsum lorem sit amet dolor ipsum lorem sit amet</p></li>
<li>
<h2>Calendar</h2>
<div id="calendar_wrap">
<table summary="Calendar">
<caption>
October 2009
</caption>
<thead>
<tr>
<th abbr="Monday" scope="col" title="Monday">M</th>
<th abbr="Tuesday" scope="col" title="Tuesday">T</th>
<th abbr="Wednesday" scope="col" title="Wednesday">W</th>
<th abbr="Thursday" scope="col" title="Thursday">T</th>
<th abbr="Friday" scope="col" title="Friday">F</th>
<th abbr="Saturday" scope="col" title="Saturday">S</th>
<th abbr="Sunday" scope="col" title="Sunday">S</th>
</tr>
</thead>
<tfoot>
<tr>
<td abbr="September" colspan="3" id="prev">« Sep</td>
<td class="pad"> </td>
<td colspan="3" id="next"> </td>
</tr>
</tfoot>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td id="today">4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>21</td>
</tr>
<tr>
<td>22</td>
<td>23</td>
<td>24</td>
<td>25</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
<tr>
<td>29</td>
<td>30</td>
<td>31</td>
<td class="pad" colspan="4"> </td>
</tr>
</tbody>
</table>
</div>
</li>
<li>
<h2>Categories</h2>
<ul>
<li>Aliquam libero</li>
<li>Consectetuer adipiscing elit</li>
<li>Metus aliquam pellentesque</li>
<li>Suspendisse iaculis mauris</li>
<li>Urnanet non molestie semper</li>
<li>Proin gravida orci porttitor</li>
<li>Aliquam libero</li>
<li>Consectetuer adipiscing elit</li>
<li>Metus aliquam pellentesque</li>
<li>Urnanet non molestie semper</li>
<li>Proin gravida orci porttitor</li>
<li>Aliquam libero</li>
<li>Consectetuer adipiscing elit</li>
<li>Metus aliquam pellentesque</li>
<li>Suspendisse iaculis mauris</li>
<li>Urnanet non molestie semper</li>
<li>Proin gravida orci porttitor</li>
<li>Metus aliquam pellentesque</li>
<li>Suspendisse iaculis mauris</li>
<li>Urnanet non molestie semper</li>
<li>Proin gravida orci porttitor</li>
<li>Metus aliquam pellentesque</li>
</ul>
</li>
</ul>
</div>
<!-- end sidebars -->
<div style="clear: both;"> </div>
</div>
<!-- end page -->
</div>
<div id="footer">
<p class="copyright">© 2009 All Rights Reserved • Design by TEMP IT Dept..</p>
<p class="link">Privacy Policy • Terms of Use</p>
</div>
</html>
Please suggest how i can change this html template to exact joomla template. Thanks.
Replace conrete content with references to module positions, message container and component output. Your template will then look like
<?php
/**
* My template
*
* #copyright (C)2013 Neetesh <neetesh#example.com>
* #author XYZ
* #link http://www.google.com
*/
// No direct access
defined('_JEXEC') or die('Restricted access');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/template.css" type="text/css" />
<link rel="icon" type="image/gif" href="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template; ?>/favicon.gif" />
<!--[if IE 7]>
<link href="templates/<?php echo $this->template ?>/css/ie7.css" rel="stylesheet" type="text/css" />
<![endif]-->
</head>
<body>
<!-- start header -->
<div id="header">
<div id="logo">
<jdoc:include type="modules" name="logo" />
</div>
<div id="menu">
<jdoc:include type="modules" name="header" />
</div>
</div>
<div id="wrapper">
<div id="page">
<div id="sidebar1" class="sidebar">
<jdoc:include type="modules" name="left" />
</div>
<div id="content">
<jdoc:include type="message" />
<jdoc:include type="component" />
</div>
<div id="sidebar2" class="sidebar">
<jdoc:include type="modules" name="right" />
</div>
<div style="clear: both;"> </div>
</div>
</div>
<div id="footer">
<jdoc:include type="modules" name="footer" />
</div>
</html>
The example above provides the module positions logo, header, left, right, and footer. Add these to the templateDetails.xml.
Next, find modules producing the sudebar content, you want, and assign them to the position, where you want to see them.

How to convert VML to png using php

I am searching for two days but just one solution VectorConvetor and it doesn't seem to work. Actually am using excanvas for InternetExplorer and want to save that image to png. IE gives VML and am not able to convert it to a png using PHP. I have heard about rendering the VML to IE and taking a screenshot using PHP but haven't found a satisfying solution to that too.
Use vml2svg.xsl and its dependencies as the imported stylesheet of an object which calls transformToXML to convert VML to SVG, then convert SVG to PNG using readImageBlob and imagemagick:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/2000/svg"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xlink="http://www.w3.org/1999/xlink"
>
<!-- INDEX:
* template:
- vml-shape
* match:
- /
- v:group
- v:shape
-->
<!-- XXXXXXXXXXXXXXXX VARIABILI GLOBALI XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->
<xsl:variable name="n-elementi">
<xsl:value-of select="count(//*)" />
</xsl:variable>
<!-- Queste variabili rappresentano una dimensione "standard" in pixel della parte di
schermo usabile per rappresentare l'immagine (escludendo la porzione occupata dalla
barra dei browser), per schermi di 17 pollici, con risoluzione 800x600.
Si usano come approssimazione quando un immagine non specifica la
sua dimensioni oppure è espressa tramite percentuale.
-->
<xsl:variable name="schermo-x">
<xsl:text>750</xsl:text>
</xsl:variable>
<xsl:variable name="schermo-y">
<xsl:text>400</xsl:text>
</xsl:variable>
<!-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->
<!-- ********************************************************************************* -->
<!-- ********************************* RADICE **************************************** -->
<!-- ********************************************************************************* -->
<xsl:template match="/">
<!-- creo un elemento svg contenitore, che non influenza nessun altra misura, serve solo
da contenitore, in quanto svg ha bisogno di un elemento radice.
Inoltre questo elemento conterrà un elemento defs con tutti i riferimenti contenuti
nel documento.
-->
<svg preserveAspectRatio="none"
overflow="visible">
<!-- NB: da aggiungere un choose per vml non contenuti in un documento html -->
<xsl:for-each select="//html:BODY | //html:body">
<!-- gestione di defs -->
<defs>
<xsl:call-template name="gestione-textpath" />
<xsl:call-template name="gestione-gradient" />
<xsl:call-template name="gestione-pattern" />
</defs>
<xsl:apply-templates />
</xsl:for-each>
</svg>
</xsl:template>
<!-- ********************************************************************************* -->
<!-- ********************************************************************************* -->
<!-- ************************ ELEMENTO GROUP ***************************************** -->
<!-- ********************************************************************************* -->
<!-- ********************************************************************************* -->
<xsl:template match="v:group">
<!-- per ogni gruppo trovaro creo un elemento svg -->
<svg>
<xsl:call-template name="core-attrs" />
<xsl:call-template name="attributo-viewbox" />
<!-- svg di default fa clipping, vml non lo fa, quindi devo impostare un attributo
per segnalare di far vedere il contenuto fuori dai margini
-->
<xsl:attribute name="overflow"><xsl:text>visible</xsl:text></xsl:attribute>
<xsl:call-template name="attributo-title" />
<!-- controllo un eventuale presenza di rotazioni -->
<xsl:variable name="r">
<xsl:call-template name="attributo-rotation" />
</xsl:variable>
<xsl:variable name="v-coordsize">
<xsl:call-template name="valore-coordsize" />
</xsl:variable>
<xsl:variable name="vb_x">
<xsl:value-of select="substring-before(normalize-space($v-coordsize),' ')" />
</xsl:variable>
<xsl:variable name="vb_y">
<xsl:value-of select="substring-after(normalize-space($v-coordsize),' ')" />
</xsl:variable>
<xsl:choose>
<!-- se ho una rotazione nell'elemento group, creo un gruppo per gestire
questa rotazione, posizionandomi nel centro della figura, perchè
svg e vml gestiscono in modo diverso le rotazioni: il primo
rispetto al punto in alto a sinistra (salvo diversa disposizione)
e l'altro rispetto al centro.
-->
<xsl:when test="$r != '0'">
<g>
<xsl:attribute name="transform">
<xsl:text>rotate(</xsl:text>
<xsl:value-of select="$r" />
<xsl:text>, </xsl:text>
<xsl:value-of select="($vb_x div 2)" />
<xsl:text>, </xsl:text>
<xsl:value-of select="($vb_y div 2)" />
<xsl:text>)</xsl:text>
</xsl:attribute>
<xsl:apply-templates />
</g>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates />
</xsl:otherwise>
</xsl:choose>
</svg>
</xsl:template>
<!-- ********************************************************************************* -->
<!-- ********************************************************************************* -->
<!-- ************************ ELEMENTO SHAPE ***************************************** -->
<!-- ********************************************************************************* -->
<!-- ********************************************************************************* -->
<xsl:template match="v:shape">
<!-- per ogni elemento shape creo un elemento svg, impostando opportunamente gli attributi
e gestendo/creando gli altri elementi per rappresentare eventuali path, testi o
immagini esterno (in quanto questi elementi sono esclusivamente contenuti in shape).
Vengono gestiti inoltre eventuali riferimenti a shapetype, considerando gli
attributi sia di quest'elemento shape, sia dei shapetype riferiti, poi si
impostano i valori dando precedenza agli attributi di shape, poi vengono quelli di
shapetype, altrimenti si usano i valori di default o quelli ereditati
-->
<!-- cerco un eventuale riferimento a un elemento shapetype -->
<xsl:variable name="id-of-shapetype">
<xsl:value-of select="substring-after(#type,'#')" />
</xsl:variable>
<!-- cerco un eventuale riferimento ad un immagine, contenuto o in questo elemento
shape o in elementi shapetype riferiti
-->
<xsl:variable name="image_present">
<xsl:choose>
<xsl:when test="(//v:shapetype[#id = $id-of-shapetype]/v:imagedata)
or (v:imagedata)" ><xsl:text>yes</xsl:text></xsl:when>
<xsl:otherwise><xsl:text></xsl:text></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- contiene yes o stringa vuota a seconda che debba o meno effettuare un riempimento:
la scelta è dovuta alla presenza di un immagine o all'impostazione di un attributo
per segnalare di non effettuare il riempiemento (fillok dell'elemento path)
-->
<xsl:variable name="no-fill">
<xsl:choose>
<xsl:when test="$image_present = 'yes'">
<xsl:text>yes</xsl:text>
</xsl:when>
<xsl:when test="v:path[#fillok = 'true']">
<xsl:text></xsl:text>
</xsl:when>
<xsl:when test="v:path[#fillok = 'false']">
<xsl:text>yes</xsl:text>
</xsl:when>
<xsl:when test="(//v:shapetype[#id = $id-of-shapetype]/v:path[#fillok = 'true'])">
<xsl:text></xsl:text>
</xsl:when>
<xsl:when test="(//v:shapetype[#id = $id-of-shapetype]/v:path[#fillok = 'false'])">
<xsl:text>yes</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text></xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- segnala se devo disegnare i bordi, determinato dal valore dell'attributo strokeok, presente
in elementi path, figli di shape o di shapetype riferiti
-->
<xsl:variable name="no-stroke">
<xsl:choose>
<xsl:when test="v:path[#strokeok = 'true']">
<xsl:text></xsl:text>
</xsl:when>
<xsl:when test="v:path[#strokeok = 'false']">
<xsl:text>yes</xsl:text>
</xsl:when>
<xsl:when test="(//v:shapetype[#id = $id-of-shapetype]/v:path[#strokeok = 'true'])">
<xsl:text></xsl:text>
</xsl:when>
<xsl:when test="(//v:shapetype[#id = $id-of-shapetype]/v:path[#strokeok = 'false'])">
<xsl:text>yes</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text></xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- creo l'elemento svg -->
<svg>
<xsl:call-template name="core-attrs" />
<!-- imposto coordsize (viewbox di svg):
prima lo cerco nell'elemento shape e se c'è lo imposto,
poi lo cerco in shapetype ed eventualmente lo imposto,
altrimenti cerco negli elementi ancestor
-->
<xsl:choose>
<xsl:when test="#coordsize">
<xsl:call-template name="attributo-viewbox" />
</xsl:when>
<xsl:when test="//v:shapetype[#id = $id-of-shapetype]">
<xsl:for-each select="//v:shapetype[#id = $id-of-shapetype]">
<xsl:call-template name="attributo-viewbox" />
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="attributo-viewbox" />
</xsl:otherwise>
</xsl:choose>
<!-- imposto le proprietà di fill e stroke:
- prima le cerco in eventuali shapetype e imposto gli
attributi;
- poi le cerco in shape, creando gli attributi che
sovrascriveranno quelli impostati in precedenza e
specifico (parametro default = no) che nel caso non
vengano trovate le proprietà non si devono impostare
i valori di default, altrimenti questi sovrascriverebbero
i valori impostati con shapetype (da notare che se una
proprietà non è presente ne in shape che in shapetype,
quando cerco i valori in st, non trovandoli vengono
impostati con i valori di default e la successiva
ricerca in shape li lascerà inalterati.
-->
<xsl:choose>
<xsl:when test="//v:shapetype[#id = $id-of-shapetype]">
<xsl:for-each select="//v:shapetype[#id = $id-of-shapetype]">
<xsl:call-template name="attributi-paint">
<xsl:with-param name="no-fill">
<xsl:value-of select="$image_present" />
</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
<xsl:call-template name="attributi-paint">
<xsl:with-param name="default">
<xsl:text>no</xsl:text>
</xsl:with-param>
<xsl:with-param name="no-fill">
<xsl:value-of select="$no-fill" />
</xsl:with-param>
<xsl:with-param name="no-stroke">
<xsl:value-of select="$no-stroke" />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="attributi-paint">
<xsl:with-param name="no-fill">
<xsl:value-of select="$no-fill" />
</xsl:with-param>
<xsl:with-param name="no-stroke">
<xsl:value-of select="$no-stroke" />
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
<!-- vml non presenta questa proprietà, tuttavia il comportamento
di vml equivale in svg alla proprietà impostata con evenodd,
mentre svg per default ha questa proprietà impostata a nonzero
-->
<xsl:attribute name="fill-rule">
<xsl:text>evenodd</xsl:text>
</xsl:attribute>
<xsl:call-template name="attributo-title" />
<xsl:variable name="r">
<xsl:call-template name="attributo-rotation" />
</xsl:variable>
<!-- gestisco il contenuto di shape, controllando l'eventuale
presenza di rotazioni (in caso affermativo creo un
gruppo con trasform, posizionandolo opportunamente), poi
cerco eventuali link associati alla figura, tramite il template
gestione-href, il quale in caso di link, creerà un elemento a e
chiamarà un template per gestire il contenuto di shape (vml-shape).
In caso non siano presenti link verrà chiamato ugualmente il
template vml-shape (senza creare l'elemento a).
-->
<xsl:choose>
<xsl:when test="$r != '0'">
<g>
<!-- devo calcolare questi valori per spostare l'asse
di rotazione: dall'angolo in alto a sx (comportamento
di default di svg) al centro della regione.
-->
<xsl:variable name="cs-w">
<xsl:call-template name="valore-coordsize">
<xsl:with-param name="parametro"><xsl:text>w</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="cs-h">
<xsl:call-template name="valore-coordsize">
<xsl:with-param name="parametro"><xsl:text>h</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:attribute name="transform">
<xsl:text>rotate(</xsl:text>
<xsl:value-of select="$r" />
<xsl:text>, </xsl:text>
<xsl:value-of select="($cs-w div 2)" /> <!-- $x + .. -->
<xsl:text>, </xsl:text>
<xsl:value-of select="($cs-h div 2)" />
<xsl:text>)</xsl:text>
</xsl:attribute>
<xsl:call-template name="gestione-href">
<xsl:with-param name="nome-template">
<xsl:text>vml-shape</xsl:text>
</xsl:with-param>
</xsl:call-template>
</g>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="gestione-href">
<xsl:with-param name="nome-template">
<xsl:text>vml-shape</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</svg>
</xsl:template>
<!-- ********************************************************************************* -->
<!-- ********************************************************************************* -->
<!-- ***************************** VML SHAPE ***************************************** -->
<!-- ********************************************************************************* -->
<!-- ********************************************************************************* -->
<xsl:template name="vml-shape">
<xsl:variable name="id-of-shapetype">
<xsl:value-of select="substring-after(#type,'#')" />
</xsl:variable>
<!-- valore di coordsize(w) / w di tutti gli elementi ancestor: rappresenta la dimensione
di un user unit.
-->
<xsl:variable name="aggiustamento">
<xsl:for-each select="v:*">
<xsl:if test="position() = last()">
<xsl:call-template name="calcola-scala" />
</xsl:if>
</xsl:for-each>
</xsl:variable>
<!-- XXXXXXXXXXXXXX GESTIONE IMAGEDATA XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->
<xsl:for-each select="//v:shapetype[#id = $id-of-shapetype]/v:imagedata">
<xsl:call-template name="elemento-imagedata" />
</xsl:for-each>
<xsl:for-each select="v:imagedata">
<xsl:call-template name="elemento-imagedata" />
</xsl:for-each>
<!-- XXXXXXXXXXXXXX GESTIONE PATH - TEXTPATH XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->
<xsl:choose>
<!-- devo rappresentare textpath -->
<xsl:when test="((v:path[#textpathok = 'true' or #textpathok = 't']) or
(//v:shapetype[#id = $id-of-shapetype]/v:path
[#textpathok = 'true' or #textpathok = 't'])) and
((v:textpath) or
(//v:shapetype[#id = $id-of-shapetype]/v:textpath))">
<xsl:choose>
<xsl:when test="v:textpath[#string]">
<xsl:for-each select="v:textpath[#string]">
<xsl:if test="position() = last()">
<xsl:call-template name="elemento-textpath" />
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:when test="v:textpath">
<xsl:variable name="stringa-st">
<xsl:for-each select="
//v:shapetype[#id = $id-of-shapetype]/
v:textpath[#string]">
<xsl:if test="position() = last()">
<xsl:value-of select="#string" />
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="v:textpath">
<xsl:if test="position() = last()">
<xsl:call-template name="elemento-textpath" >
<xsl:with-param name="stringa">
<xsl:value-of select="$stringa-st" />
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:when test="//v:shapetype[#id = $id-of-shapetype]/v:textpath">
<xsl:variable name="path-id">
<xsl:choose>
<xsl:when test="v:path[#v != ''] or #path != ''">
<xsl:value-of select="count(preceding::v:*) +
count(ancestor::v:*)" />
</xsl:when>
<xsl:otherwise>
<xsl:text></xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:for-each select="
//v:shapetype[#id = $id-of-shapetype]/v:textpath">
<xsl:if test="position() = last()">
<xsl:choose>
<xsl:when test="$path-id = ''">
<xsl:call-template name="elemento-textpath">
<xsl:with-param name="aggiustamento">
<xsl:value-of select="$aggiustamento" />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="elemento-textpath" >
<xsl:with-param name="path-id">
<xsl:value-of select="$path-id" />
</xsl:with-param>
<xsl:with-param name="aggiustamento">
<xsl:value-of select="$aggiustamento" />
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise><!-- in teoria qui non dovrebbe andarci mai -->
<XXX></XXX>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- devo rappresentare path -->
<xsl:when test="v:path[#v != '']">
<xsl:for-each select="v:path[#v != '']">
<xsl:if test="position() = last()">
<xsl:call-template name="gestione-path" />
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:when test="#path != ''">
<xsl:call-template name="elemento-path">
<xsl:with-param name="v">
<xsl:value-of select="#path" />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="//v:shapetype[#id = $id-of-shapetype]">
<xsl:choose>
<xsl:when test="v:path[#v != '']">
<xsl:for-each select="v:path[#v != '']">
<xsl:if test="position() = last()">
<xsl:call-template name="gestione-path" />
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:when test="#path != ''">
<xsl:call-template name="elemento-path">
<xsl:with-param name="v">
<xsl:value-of select="#path" />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
<!-- XXXXXXXXXXXXXXXXXXX GESTIONE TEXTBOX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->
<xsl:if test="(v:textbox)">
<xsl:call-template name="elemento-textbox">
<xsl:with-param name="id-of-shapetype">
<xsl:value-of select="$id-of-shapetype" />
</xsl:with-param>
<xsl:with-param name="aggiustamento">
<xsl:value-of select="$aggiustamento" />
</xsl:with-param>
</xsl:call-template>
</xsl:if>
<xsl:apply-templates />
</xsl:template>
<!-- ********************************************************************************* -->
<!-- ********************************************************************************* -->
<!-- ************************ ELEMENTO SHAPETYPE ************************************* -->
<!-- ********************************************************************************* -->
<!-- ********************************************************************************* -->
<xsl:template name="elemento-shapetype">
<!-- shapetype viene gestito quando e' richiamato da shape -->
</xsl:template>
<!-- ********************************************************************************* -->
<!-- ********************************************************************************* -->
<!-- ************************ TEMPLATE GESTIONE-SHAPETYPE **************************** -->
<!-- ********************************************************************************* -->
<!-- ********************************************************************************* -->
<xsl:template name="gestione-shapetype">
<!-- shapetype viene gestito quando e' richiamato da shape -->
</xsl:template>
<!-- ********************************************************************************* -->
<!-- ********************************************************************************* -->
<!-- ************************ ELEMENTO A ***************************************** -->
<!-- ********************************************************************************* -->
<!-- ********************************************************************************* -->
<xsl:template match="html:a">
<xsl:choose>
<xsl:when test="#href">
<a>
<xsl:attribute name="xlink:href">
<xsl:value-of select="#href" />
</xsl:attribute>
<xsl:apply-templates />
</a>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

Categories