Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Need help on XSLT 2.0 transformation.

Input xml :

<Employee>
<Post>Manager</Post>
</Employee>

pseudo code :

if(Employee/Post = 'Manager') then
Associate/High = 'Band'
else
Associate/Low = 'Band'

Output xml :

<Associate>
<High>Band</High>
</Associate>

<Associate>
<Low>Band</Low>
</Associate>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
133 views
Welcome To Ask or Share your Answers For Others

1 Answer

Construct an element dynamically with xsl:element. Other than that, your pseudo code is already pretty accurate.

XSLT Stylesheet

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />

    <xsl:template match="Employee">
      <Associate>
          <xsl:element name="{if (Post = 'Manager') then 'High' else 'Low'}">
              <xsl:value-of select="'Band'"/>
          </xsl:element>
      </Associate>
    </xsl:template>

</xsl:transform>

XML Output

<Associate>
   <High>Band</High>
</Associate>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...