-1
<?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>

I have to promote to "Administrator" a random user using XPath.
How can I do it?

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by fpmurphy
0

Here is a stylesheet which will do what you want

<?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>

Edited by fpmurphy: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.