473,326 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

[PHP5 & DOM] element extracted from doc suddenly not found in insertBefore() -- NS problem

Code and problem are from PHP5:

When I execute the following piece of code, the DomException is thrown with
a message: Not Found Exception.
I assume this means that the node I extracted from the DomDocument using
getElementsByTagName() isn't found when I use insertBefore(). I blame the
namespace :-)
When I replace the getElementsByTagName( 'xsl:template' ), I get the "no
template tag found message" in the else.
What is the NS-safe way to insert a xsl:param tag before the xsl:template
tags?

<?php

$xsl = <<<XSL
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="xhtml/basic.xhtml.xsl" />
<xsl:import href="xhtml/search.xhtml.xsl" />
<xsl:import href="xhtml/news.xhtml.xsl" />

<xsl:output
method="xml"
omit-xml-declaration="no"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
indent="yes"
media-type="text/html"
/>

<xsl:param name="updatetime" />

<xsl:template match="/">
<xsl:apply-imports />
</xsl:template>

</xsl:stylesheet>
XSL;

$stylesheet = DomDocument::loadXML( $xsl );
$temp_list = $stylesheet->getElementsByTagName( 'template' );
if( $temp_list && $temp_list->item(0) ) {
$template = $temp_list->item(0);
$param = $stylesheet->createElement( 'xsl:param' );
try {
$stylesheet->insertBefore( $param, $template );
} catch( DomException $e ) {
print "Exception ".$e->getMessage();
print "\n";
print $template->tagName;
}

}
else {
die( "No template tag found" );
}
?>

Thanks in advance.
Rutger Claes
--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me pgp:0x3B7D6BD6
Overflow on /dev/null, please empty the bit bucket.

Jul 17 '05 #1
3 2812
there must be a method similar to createElement() which creates an element
in a given namespace. also check out
http://us2.php.net/manual/en/functio...ytagnamens.php

konstantin

"Rutger Claes" <rg*@rgc.tld-of-belgium> wrote in message
news:11***************@seven.kulnet.kuleuven.ac.be ...
Code and problem are from PHP5:

When I execute the following piece of code, the DomException is thrown
with
a message: Not Found Exception.
I assume this means that the node I extracted from the DomDocument using
getElementsByTagName() isn't found when I use insertBefore(). I blame the
namespace :-)
When I replace the getElementsByTagName( 'xsl:template' ), I get the "no
template tag found message" in the else.
What is the NS-safe way to insert a xsl:param tag before the xsl:template
tags?

<?php

$xsl = <<<XSL
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="xhtml/basic.xhtml.xsl" />
<xsl:import href="xhtml/search.xhtml.xsl" />
<xsl:import href="xhtml/news.xhtml.xsl" />

<xsl:output
method="xml"
omit-xml-declaration="no"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
indent="yes"
media-type="text/html"
/>

<xsl:param name="updatetime" />

<xsl:template match="/">
<xsl:apply-imports />
</xsl:template>

</xsl:stylesheet>
XSL;

$stylesheet = DomDocument::loadXML( $xsl );
$temp_list = $stylesheet->getElementsByTagName( 'template' );
if( $temp_list && $temp_list->item(0) ) {
$template = $temp_list->item(0);
$param = $stylesheet->createElement( 'xsl:param' );
try {
$stylesheet->insertBefore( $param, $template );
} catch( DomException $e ) {
print "Exception ".$e->getMessage();
print "\n";
print $template->tagName;
}

}
else {
die( "No template tag found" );
}
?>

Thanks in advance.
Rutger Claes
--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me
pgp:0x3B7D6BD6
Overflow on /dev/null, please empty the bit bucket.

Jul 17 '05 #2
konsu wrote:
there must be a method similar to createElement() which creates an element
in a given namespace. also check out
http://us2.php.net/manual/en/functio...ytagnamens.php
konstantin

If you replace the code with all the ...NS() functions the result is
identical. The problem is that when you extract a node from the document
and use it to insert another, the node suddenly is not found.

New code:
$xml = DomDocument::loadXML( $xsl );

$t_list =
$xml->getElementsByTagnameNS( 'http://www.w3.org/1999/XSL/Transform',
'template' );
if( $t_list && $t_list->item(0) ) {
print $t_list->item(0)->tagName;

$new_tag = $xml->createElementNS( 'http://www.w3.org/1999/XSL/Transform',
'param' );
try {
$xml->insertBefore( $new_tag, $t_list->item(0) );
print $xml->saveXML();
} catch( DomException $e ) {
print $e->getMessage();
}
}
else {
die( "No tags found" );
}

xsl stays the same.
This still gives "Not found error"

Is this a bug in the PHP5 DOM implementation?
"Rutger Claes" <rg*@rgc.tld-of-belgium> wrote in message
news:11***************@seven.kulnet.kuleuven.ac.be ...
Code and problem are from PHP5:

When I execute the following piece of code, the DomException is thrown
with
a message: Not Found Exception.
I assume this means that the node I extracted from the DomDocument using
getElementsByTagName() isn't found when I use insertBefore(). I blame
the namespace :-)
When I replace the getElementsByTagName( 'xsl:template' ), I get the "no
template tag found message" in the else.
What is the NS-safe way to insert a xsl:param tag before the xsl:template
tags?

<?php

$xsl = <<<XSL
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="xhtml/basic.xhtml.xsl" />
<xsl:import href="xhtml/search.xhtml.xsl" />
<xsl:import href="xhtml/news.xhtml.xsl" />

<xsl:output
method="xml"
omit-xml-declaration="no"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
indent="yes"
media-type="text/html"
/>

<xsl:param name="updatetime" />

<xsl:template match="/">
<xsl:apply-imports />
</xsl:template>

</xsl:stylesheet>
XSL;

$stylesheet = DomDocument::loadXML( $xsl );
$temp_list = $stylesheet->getElementsByTagName( 'template' );
if( $temp_list && $temp_list->item(0) ) {
$template = $temp_list->item(0);
$param = $stylesheet->createElement( 'xsl:param' );
try {
$stylesheet->insertBefore( $param, $template );
} catch( DomException $e ) {
print "Exception ".$e->getMessage();
print "\n";
print $template->tagName;
}

}
else {
die( "No template tag found" );
}
?>

Thanks in advance.
Rutger Claes
--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me
pgp:0x3B7D6BD6
Overflow on /dev/null, please empty the bit bucket.


--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me pgp:0x3B7D6BD6
Long computations which yield zero are probably all for naught.

Jul 17 '05 #3
here is something that does not fail but it shows no output for saveXML. i
did not spend time trying to figure out why.

$xml = new DOMDocument;
$xml->loadXML($xsl);

$t_list = $xml->getElementsByTagnameNS(
'http://www.w3.org/1999/XSL/Transform','template' );
if( $t_list && $t_list->item(0) )
{
echo($xml->documentElement->tagName);
$new_tag = $xml->createElementNS(
'http://www.w3.org/1999/XSL/Transform','param' );
try
{
$xml->documentElement->insertBefore( $new_tag, $t_list->item(0) );
echo($xml->saveXML());
}
catch( DomException $e )
{
echo($e->getMessage());
}
}
else
{
die( "No tags found" );
}

"Rutger Claes" <rg*@rgc.tld-of-belgium> wrote in message
news:11***************@seven.kulnet.kuleuven.ac.be ...
konsu wrote:
there must be a method similar to createElement() which creates an
element
in a given namespace. also check out

http://us2.php.net/manual/en/functio...ytagnamens.php

konstantin


If you replace the code with all the ...NS() functions the result is
identical. The problem is that when you extract a node from the document
and use it to insert another, the node suddenly is not found.

New code:
$xml = DomDocument::loadXML( $xsl );

$t_list =
$xml->getElementsByTagnameNS( 'http://www.w3.org/1999/XSL/Transform',
'template' );
if( $t_list && $t_list->item(0) ) {
print $t_list->item(0)->tagName;

$new_tag = $xml->createElementNS( 'http://www.w3.org/1999/XSL/Transform',
'param' );
try {
$xml->insertBefore( $new_tag, $t_list->item(0) );
print $xml->saveXML();
} catch( DomException $e ) {
print $e->getMessage();
}
}
else {
die( "No tags found" );
}

xsl stays the same.
This still gives "Not found error"

Is this a bug in the PHP5 DOM implementation?
"Rutger Claes" <rg*@rgc.tld-of-belgium> wrote in message
news:11***************@seven.kulnet.kuleuven.ac.be ...
Code and problem are from PHP5:

When I execute the following piece of code, the DomException is thrown
with
a message: Not Found Exception.
I assume this means that the node I extracted from the DomDocument using
getElementsByTagName() isn't found when I use insertBefore(). I blame
the namespace :-)
When I replace the getElementsByTagName( 'xsl:template' ), I get the "no
template tag found message" in the else.
What is the NS-safe way to insert a xsl:param tag before the
xsl:template
tags?

<?php

$xsl = <<<XSL
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="xhtml/basic.xhtml.xsl" />
<xsl:import href="xhtml/search.xhtml.xsl" />
<xsl:import href="xhtml/news.xhtml.xsl" />

<xsl:output
method="xml"
omit-xml-declaration="no"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
indent="yes"
media-type="text/html"
/>

<xsl:param name="updatetime" />

<xsl:template match="/">
<xsl:apply-imports />
</xsl:template>

</xsl:stylesheet>
XSL;

$stylesheet = DomDocument::loadXML( $xsl );
$temp_list = $stylesheet->getElementsByTagName( 'template' );
if( $temp_list && $temp_list->item(0) ) {
$template = $temp_list->item(0);
$param = $stylesheet->createElement( 'xsl:param' );
try {
$stylesheet->insertBefore( $param, $template );
} catch( DomException $e ) {
print "Exception ".$e->getMessage();
print "\n";
print $template->tagName;
}

}
else {
die( "No template tag found" );
}
?>

Thanks in advance.
Rutger Claes
--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me
pgp:0x3B7D6BD6
Overflow on /dev/null, please empty the bit bucket.


--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me
pgp:0x3B7D6BD6
Long computations which yield zero are probably all for naught.

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stanimir Stamenkov | last post by:
I've wondered if it is right thing to do: element.parentNode.insertBefore(element, beforeElement); where 'beforeElement' is one of the 'element.parentNode.childNodes'? First, I've used: ...
13
by: sneill | last post by:
I know its possible to dynamically remove elements from the DOM, but rather than deleting them forever, is it possible to 'capture' them and save them as an object variable so they can be reused...
5
by: Richard Lewis | last post by:
Hello Pythoners, I'm currently writing some Python to manipulate a semi-structured XML document. I'm using DOM (minidom) and I've got working code for transforming the document to HTML files and...
14
by: hgraham | last post by:
Hi, I'm trying to understand how to work the dom, and all I'm trying to do is insert a link right before another link in the html based on it's href value. This isn't a real world example - I'm...
4
by: Michel Verhagen | last post by:
Hi, I want to create a DTD in an XML file in memory. The XML file is created using the DOM in C#. I am new to all this, but couldn't find anything about creating DTD's using the DOM (well, I...
5
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
7
by: dennis.sprengers | last post by:
I am trying to write an editor object, which adds some functionality and a toolbar to every textarea with a "form-textarea" class. Both FF and IE generate an error in line 20...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.