Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Simple multi replace function in XSLT

$
0
0

I'm new to XSLT, but have a nicely working script that I'd like to refine by replacing numeric values for field 'Type' with related strings in the result. In JavaScript, I'd use a switch function but I need the equivalent in XSL

My Table Definition:

  <table>
  <tr bgcolor="#6FB6E2">
      <th>User Field</th>
      <th>Name</th>
      <th>Identifier</th>
      <th>Type</th>
      <th>Parameters</th>
      <th>Locked</th>
      <th>Mandatory</th>
  </tr>
  <xsl:for-each select="PREFERENCES/USERCOLUMNS/userColumn">
            <tr>
              <td>USER<xsl:value-of select="@index"/></td>
              <td><xsl:value-of select="@name"/></td>
              <td><xsl:value-of select="@identifier"/></td>
              <td><xsl:value-of select="@type"/></td>
              <td><xsl:value-of select="@parameters"/></td>
              <td><xsl:value-of select="@locked"/></td>
              <td><xsl:value-of select="@mandatory"/></td>
              </tr>
    </xsl:for-each>
  </table>

My replacement value sets for field "type":

From: ('1', '2', '3', '4', '5')

To: ('Grouping', 'Multi Grouping', 'Hierarchy', 'Multi Hierarchy', 'Linked Hierarchy')

My Sample XML:

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<PREFERENCES>
<USERCOLUMNS count="168">
  <userColumn index="33" identifier="user.custom.language" name="Language" locked="false" mandatory="false" type="1"/>
  <userColumn index="41" identifier="user.basic.host.presenter" name="Host/Presenter" locked="false" mandatory="false" type="2"/>
  <userColumn index="42" identifier="user.basic.subject.line" name="Subject/Line" locked="false" mandatory="false" type="3"/>
  <userColumn index="54" identifier="user.extended.best.take" name="Best Take" parameters="YES&#10;No&#10;Possible" locked="false" mandatory="false" type="4"/>
  <userColumn index="55" identifier="user.basic.shoot.date" name="Shoot Date" locked="false" mandatory="false" type="5"/>
 </USERCOLUMNS>
</PREFERENCES>

As a bonus question, the "parameters" field includes line feeds as separators for multiple values, but they are not being read as such. In the fourth line, userColumn index="54" the "parameters field has a value of "YES&#10;No&#10;Possible" which should be three lines showing a word on three lines... Is there anyway to have the table word wrap so that the line feeds are displayed correctly?


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>