| | |
[PHP] How to change a value with XPath
Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2009
Posts: 1
Reputation:
Solved Threads: 0
XML, XSLT and XPATH Syntax (Toggle Plain Text)
<?xml version="1.0"?> <staff> <user> <id>A</id> <rank>User</rank> </user> <user> <id>B</id> <rank>User</rank> </user> <user> <id>C</id> <rank>Administrator</rank> </user> </staff>
How can I do it?
•
•
Join Date: Oct 2008
Posts: 95
Reputation:
Solved Threads: 5
Here is a stylesheet which will do what you want
XML, XSLT and XPATH Syntax (Toggle Plain Text)
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <!-- pass in as -param uid "'value'" --> <xsl:param name="uid"/> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <xsl:element name="staff"> <xsl:apply-templates select="//user"/> </xsl:element> </xsl:template> <!-- output nodes that match --> <xsl:template match="user"> <xsl:if test="id=$uid"> <xsl:element name="user"> <xsl:element name="id"><xsl:value-of select="$uid"/></xsl:element> <xsl:element name="rank">Administrator</xsl:element> </xsl:element> </xsl:if> <xsl:if test="id!=$uid"> <xsl:copy-of select="."/> </xsl:if> </xsl:template> </xsl:stylesheet>
Last edited by fpmurphy; Sep 9th, 2009 at 12:01 pm.
![]() |
Similar Threads
- PHP URL variables and if statement (PHP)
- Basic PHP Includes (PHP)
- Creating a login page in PHP (PHP)
- SMTP mail settings with PHP (PHP)
- PHP script HELP (PHP)
- Learning PHP but problem with script (PHP)
- Trying to get PHP to send smtp through sendmail 8 (PHP)
- Using PHP to Send Email to a single DB list member every 24 hrs. (PHP)
- table in php browser incompat. prob. (HTML and CSS)
Other Threads in the XML, XSLT and XPATH Forum
- Previous Thread: XPath expression for <td> tag having "Type" as textContent in any of its childNodes
- Next Thread: my swf not loading xml at server
| Thread Tools | Search this Thread |
api blogger blogging code delete development dynamiccreationofnvariablesinxslt error firstthreecharacterofastringrequired flipbook gdata google html include java link linspire linux microsoft news node openoffice overwrite precedence programming rss standards swf template transform variable w3c web xml xmlnotloading xmlonserver xsl xslt





