Jump to content

boen_robot

Members
  • Posts

    8,493
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by boen_robot

  1. boen_robot

    PHP and XML

    Try something like this: $dom = new DomDocument;$dom->Load('test.xml');$xpath = new DOMXpath($dom);$node = $xpath->query("//*[@uri='sip:vivek@company.org'");echo $node->nodeName . "\n";$dom->removeChild($node);$dom->save('test.xml'); If I'm guessing right, by selecting $GLOBALS['dom']->lastChild you've actually been removing the last child of root of the complete document, which as it so happens is the root element and all of it's content.
  2. Opps. Busted. You're right. It had to be either "//peoples" or another explicit XPath expression to limit the execution (for example "/*/peoples" will only execute the template for "peoples" who are childs of the root element). The way I wrote it would have executed the tepmlate if the root element was "peoples".Right again, the root and root element are two different things. The root includes the root element, alongside any processing instructions and comments that might appear before the root element. "/*" on the other hand maches only the root element.
  3. Sure you're not...XPath is sencetive to a namespace, that's all.If you change /c to /c{aaa} where the contents of the parenthesis is the namespace URI, it will work. If you want to select that element regardless of it's namespace, use /*[local-name()='c']
  4. The first document.getElementById("id1").write("something") is closer. However, the major problem is that you're accessing the current document. You need to first load the XML document (from the window.location as you're suggesting) and then find the node and set it. Something like that maybe (not tested and will probably not work): var xmlLocation = window.location;xmlDoc=loadXMLDoc(xmlLocation);var x=xmlDoc.getElementsByTagName("Header"); for(i=0;i<x.length;i++) { x.item(i).setAttribute("GET-KEY","GET-VALUE"); } And in XSLT then, the check would be: <xsl:if test="@GET-KEY = 'GET-VALUE'"><!--Whatever actions--></xsl:if> I'm not good in XML DOM, so I can't really help you for editing the contents of the Header.What you were thinking is probably the only method.
  5. Define some sort of root template that will only apply the appropriate one and (optionally) will add some wrappers around the table.Try it like that: <?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html" indent="yes"/><xsl:template match="/"><!--Add anything you wish to appear before the table--><xsl:apply-templates select="peoples"/><!--Add anything you wish to appear after the table--></xsl:template> <xsl:template match="peoples"> <table> <tr> <td>Name</td> <td>Age</td> </tr> <xsl:for-each select="people"> <tr> <td><xsl:value-of select="name"/></td> <td><xsl:value-of select="age"/></td> </tr> </xsl:for-each> </table></xsl:template></xsl:stylesheet> XSLT has a few build in templates that allow a good and easy workflow. Two of those templates are <xsl:template match="*|/"> <xsl:apply-templates/></xsl:template> and <xsl:template match="text()|@*"> <xsl:value-of select="."/></xsl:template> Unless you create your own template to override those ones, they will get executed.Scince you didn't had a rule for your root node, the templates for other elements are applied. Scince there isn't a template for <quantity>, a template is executed for it's inner nodes. The only inner node is the text node, which according to the second built-in template is just written.
  6. I can't believe W3C have that warning. The others- OK, but this one: funny.You might not be getting it if you're inputting your CSS directly (as code). Try giving it by a URL.
  7. boen_robot

    Positioning

    Some code and/or a link to a sample page might do better explaining than one could ever do.
  8. If you have PHP5, you may also use the file_put_contents() function. I personally find it a lot easier and just love it.
  9. What you're showing is still part of the complete XSLT file. That's why I bolded the word "complete". Imagine your whole XSLT file looking like any of the above fragments without anything else in it. It won't be valid.By "access" an element I mean... well... how should I put it. With document.write("something") you write "something" over the whole document. The complete source code of the currect document becomes "something". And with document.getElementById("var").write("something") you write "something" inside an element inside the document, that has an ID of "var". So, by using getElementById(), you've accessed an element with the targeted ID. By using XML DOM objects, you can access nodes in an XML based document and add/change/remove such.Your XSLT approach seems a lot better. Infact, here's an idea. Perform a check in XSLT based on the value of an XML node (be it attribute or element). Then, with a JavaScript inside the XSLT, change the value of that node or better yet - just create a new such node with the specified value. The XSLT should then redo the transformation, taking the new value into account.
  10. 8.Can I have string replacement/regular exp​ressions/custom XPath functions/[insert apparently missing cool feature] in XSLT?Natively in XSLT 1.0, you can't. You can do these things, and quite a few more in XSLT 2.0. However, keep in mind that most processors around are XSLT 1.0 processors. This includes the XSLT processors of all browsers, Xalan (The Apache Foundation's XSLT processor), libxslt (PHP5's XSLT processor), MSXML (ASP(.NET)'s built in XSLT processor).If you program in a COM aware environment (e.g. PHP under Windows) or a .NET or JAVA runtime, you can try to use Altova XML as your XSLT processor. If you run in a .NET or JAVA runtime, you could also try to use SAXON. If you have another kind of environment, you can only use either of these processor from the command line (assuming you can execute programs from the command line).If installing an XSLT 2.0 processor is not an option for whatever reason, you can port some of XSLT 2.0's functionality to XSLT 1.0 by the use of EXSLT extensions. Some of them are natively supported by some XSLT processors. You can check if your XSLT processor has a native support for a certain element/function by the use of the function-available() and element-available() XSLT functions. See EXSLT's "How to Use EXSLT" page for detailed instructions on how to use EXSLT extensions in your stylesheets.
  11. 6. How to do XSLT processing in PHP?In PHP4, there was the Sablotron XSLT processor, which never reached a stable state, which is why it was removed from PHP5 in favor of libxslt. Exactly because of the above, it is highly recommended that you move to PHP5 if you need to process XSLT. XML support (in general) is far better in PHP5.On Windows, in order to use libxslt, you need to first install PHP from an archive, so that you have the php_xsl.dll extension. Then, in php.ini, be sure that you've set the "extension_dir" to the proper path where this file is. If you've installed PHP in "C:\PHP5\", then that directive needs to be set with this line: extension_dir = "C:\PHP5\ext" also, find and uncomment the line extension=php_xsl.dll and finally restart your web server (be it Apache, IIS or whatever).For sample codes to get you started with libxslt, refer to this article or this one. Read the XSL functions reference for more things you can do with libxslt in PHP.
  12. 4. I want to display the contents of an XML in parts and maybe even add some controls on a user friendly page. How can I do this in XSLT?andreathedove (a forum member) first made an XSLT for that, which was very broken, but still served as a start. boen_robot took the liberty of fixing and generalizing it as much as he could. You can find the latest version in the original topic called Paging XML. Tweak the various parameters according to your needs, check the paths to match the path of your paged content and adjust the pagedElement template. If anything is unclear, PM boen_robot with what exactly you have problems with and tell him what to write to make it more clear.It should be noted that XSLT isn't particularly suitable for processing large XML datasets, because it works with the XML's DOM (or another kind of tree) representation under the hood. The DOM (or the tree) however quickly gets very big (RAM wise), so if you go overboard with displaying XML data like that, you'll quickly exhaust your server/browser limits.
  13. 2. What does it mean to "transform XML with XSLT on XSLT processor"?/Can I make my XML do this with XSLT?Those questions are closely related. Most people find it hard to grasp how the whole XSLT process works. There are many topics on the net to show that. There is even a post here in this forum that attempts to explain the XSLT process in detail and how it differs from XSL-FO.In short, what you need to understand is that instead of manipulating "the look" of your XML or making the XML "do" things, an XSLT processor turns it into another code (most oftenly XHTML) and that code is then rendered by the browser's rendering engine or (more rarely) taken by another application for another transformation and/or processing.
  14. I don't see any difference between your input and ouput .If the only thing you have to remove is the hyphen, then a simple translate() will do it: translate('20061130-093023','-','') will output 20061130093023
  15. After recently doing a WhoIS check on my IP, I know my ISP has bought it's IPs from some company located in Amsterdam, so the results do not surprise me at all.Note that all of the above results are in Kbps, not in KB/s (just to clarity).
  16. XSLT is a transformation language. Think of what your end code is supposed to look like and think how you want to manipulate the ouput, not how you want to manipulate the XSLT and/or XML itself.Or better yet, do think how you want to manipulate the XML and XSLT. But do not expect one to be aware of the other.Which brings us to your problem. If what I think is right <script type="text/javascript">if(str == "started"){ document.write("<td><img src="blue1.jpg"></img></td>")}</script> Is actually referring to a rewrite in the XSLT itself. So, what you've define is that when str == "started", your complete XSLT will look like <td><img src="blue1.jpg"></img></td> which is obviously not a valid XSLT stylesheet. Instead, access the current element and use write() over it.
  17. There isn't. In XML, you define the name of your nodes and what's best really depends on what you'll be using the XML for.A pure rule of thumb I can personally give you is to you is to use additional nodes to describe similar pieces of data, rather then making elements with similar names. For example, instead of<element1/><element2/>use something like<element id="1"/><element id="2"/>This will make it a lot easier to create proper and more straight XPath expressions.[edit]Thank you. That's how I wanted my avatar to look .[/edit]
  18. Oh, yeah. My fault that I forgot to tell you. You need to "clear:both;" all elements that are inside the floated elements.What method exactly are you using in your first attempt? If all childs of the list are truly blocks, then they should be on a separate line. If it contains floats in any sort of way, the clear property is still a must.
  19. In this topic, We'll try to gather some of the problems in XSLT most of you will be having and provide solutions to them.Table of contents: How to create attributes in XSLT? What does it mean to "transform XML with XSLT on XSLT processor"?/Can I make my XML do this with XSLT? How to show the results of an XSLT transformation inside HTML pages? I want to display the contents of an XML in parts and maybe even add some controls on a user friendly page. How can I do this in XSLT? I want to display a sequence of elements on the same level (for example "/root_element/first_child_that_repeats_lots_of_times") in a table with a fixed predefined number of columns. How can I do that? How to do XSLT processing in PHP? How to do XSLT processing in Cold Fusion? Can I have string replacement/regular exp​ressions/custom XPath functions/[insert apparently missing cool feature] in XSLT? Where can I get more information on XSLT?
  20. I don't think that's possible at all. It's part of the image format's specification. PNGs can be drawn progressively, but even they can't be drawn horizontally.
  21. I'm confused as to what position are you in right now.As far as I'm aware, the process of creation is to set up the WS server to accept certain types of SOAP requests and return certain types of SOAP responses, which the other application then deals with. In order for the other application to know what to expect in your response and to know what to send, it needs a WDSL file which you of course publish if you want your WS to be usable. Otherwise you save local copies and no one gets your WDSL, thus it doesn't use your WS.I don't have any experience is WS yet, so I'm not sure of all this, but that's just the impression I've got. If you already consume WS, you might be the one to clarify how.
  22. First stop, I don't think you need the <xsl:template match="/Level3"> </xsl:template> And if the first XML is processed properly, this might mean your processor doesn't support the document() function. What is your processor anyway?
  23. What I meant was to open input.xml in IE. If that XML has<?xml-stylesheet type="text/xsl" href="file1.xsl"?>The MSXML3 processor which IE is using will be started and what you'll see will be the result of an XSLT transformation using the file1.xsl file.Running the same file with FF will start the Transformiix XSLT processor.In other words, I just meant "use another XSLT processor".
  24. The problem may be some sort of bug in biztalk. Try running the same XML and XSLT pair with IE or perhaps Firefox (NOT in Opera!). If you have some sort of server side scripting processor (PHP5's libxslt for example), try using it too. It should work in all of them.
×
×
  • Create New...