troubleshooting Question

XSLT : if one element is of value X change another element to value Y

Avatar of directxBOB
directxBOBFlag for Ireland asked on
XML
6 Comments1 Solution258 ViewsLast Modified:
I have this XML File:

<?xml version="1.0"?>
<details>
      <me>
            <email>ABCDE@hotmail.com</email>
            <name>name1</name>
            <password>123456</password>
            <character>player</character>
      </me>
      <me>
            <email>EDCBA@hotmail.com</email>
            <name>name2</name>
            <password>123456</password>
            <character>player</character>
      </me>
</details>

if element email = ABCDE@hotmail.com

then I want to change name to be MY NAME

I use the following:



<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:output method="xml"/>
      <xsl:template match="email">
            <xsl:variable name="email" select="//email"/>
            <xsl:choose>
                  <xsl:when test="$email='ABCDE@hotmail.com'">
                        <email>ABCDE@hotmail.com</email>
                        <xsl:variable name="name" select="//name"/>
                        <xsl:choose>
                              <xsl:when test="$name='name1'">
                                    <name>MYNAME</name>
                              </xsl:when>
                        </xsl:choose>
                  </xsl:when>
                  <xsl:otherwise>
                        <xsl:copy-of select="."/>
                  </xsl:otherwise>
            </xsl:choose>
      </xsl:template>
            <xsl:template match="*">
            <xsl:copy>
                  <xsl:copy-of select="@*" />
                  <xsl:apply-templates />
            </xsl:copy>
      </xsl:template>
</xsl:stylesheet>



any ideaS?
ASKER CERTIFIED SOLUTION
Gertone (Geert Bormans)
Information Architect
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros