2

Here's the following pseudo code I'm achieving:

if {./jobtype eq 1} jobbackgroundcolor='#ffffff';
if {./jobtype eq 2} jobbackgroundcolor='#000000';
if {./jobtype eq 3} jobbackgroundcolor='#ababab';
if {./jobtype eq 4} jobbackgroundcolor='#eac123';
if {./jobtype eq 5} jobbackgroundcolor='#eacddd';

I don't know how to set the jobbackgroundcolor to a variable so I can essentially do this:

<a href="" style="background-color:{$jobbackgroundcolor}"></a>

Of course the code is pseudo code so any concrete implementations would be great.

1
  • 2
    I believe you are looking for xsl:choose. Please post an example of the input and the expected output, if you want a more detailed answer. Commented Jan 19, 2016 at 18:52

1 Answer 1

1

XSLT 2.0 solution

Given this input XML

<jobtype>3</jobtype>

this XSLT

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

  <xsl:template match="/">
    <xsl:variable name="jt" select="number(jobtype)"/>
    <a>
      <xsl:if test="$jt = (1 to 5)">
        <xsl:attribute name="style"
                       select="concat('background-color:',
                               ('#ffffff','#000000','#ababab','#eac123','#eacddd')[$jt])"/>
      </xsl:if>
    </a>
  </xsl:template>

</xsl:stylesheet>

will output this XML

<a style="background-color:#ababab"/>

as requested.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.