tags:

views:

282

answers:

3

I am not a programmer, but am trying to transform some data. The data contained in my xml field "Source/End/Edgecode" looks like -000016 I want to remove the leading dash. I thought I could use abs or right, but I don't know the correct syntax. Thanks for any help... * FROM CLIP NAME:

<xsl:template name="frame_to_tc">
    <xsl:param name="frame"/>
    <xsl:variable name="hh" select="($frame div $fph)"/>
    <xsl:variable name="rh" select="($frame mod $fph)"/>
    <xsl:variable name="mm" select="($rh div $fpm)"/>
    <xsl:variable name="rm" select="($rh mod $fpm)"/>
    <xsl:variable name="ss" select="($rm div $fps)"/>
    <xsl:variable name="rs" select="($rm mod $fps)"/>
    <xsl:variable name="ff" select="($rs mod $fps)"/>
    <xsl:value-of select="format-number(floor($hh),'00')"/>
    <xsl:text>:</xsl:text>
    <xsl:value-of select="format-number(floor($mm),'00')"/>
    <xsl:text>:</xsl:text>
    <xsl:value-of select="format-number(floor($ss),'00')"/>
    <xsl:text>:</xsl:text>
    <xsl:value-of select="format-number(floor($ff),'00')"/>

+1  A: 

You can use a simple substring.

<xsl:value-of select="substring($yourVariable, 2)"/>
<!-- In XSLT, the index starts from 1, so here you are taking a substring starting from the second character, in essence, leaving out the hyphen-->

Or even the node directly instead of the variable..

<xsl:value-of select="substring(/Your/Path/Here, 2)"/>

Since you are not specifying a specific number of characters to return, it will return the rest of the string completely. You can restrict the number of characters returned which is done by adding a comma and then specifying a second length upto which to cut) Ex: substring(/Your/Path/Here , 2, 5)

This will cut from the 2nd character upto five characters, If the string is "1234567" it will return "23456".

NOTE: This is assuming that you only want to remove the leading hyphen. If you want to remove the leading zeroes as well, a number() typecast should do the trick.

Thiyagaraj
A: 

to remove the leading dash, try this XPath function:

  <xsl:value-of select="substring-after($x,'-')"/>
Jweede
What happens if the '-' is missing? :)
Thiyagaraj
yeh, this was an offhand solution. This assumes EVERY string has a - somewhere in it.
Jweede
+1  A: 
<xsl:template name="abs">
  <xsl:param name="input" select="0">

  <xsl:variable name="num" select="number(input)" />    
  <xsl:choose>
    <xsl:when test="$num &gt;= 0">
      <xsl:value-of select="$num" />
    </xsl:when>
    <xsl:when test="$num &lt; 0">
      <xsl:value-of select="-1 * $num" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$input" />
    </xsl:otherwise>
  </xsl:choose>
<xsl:template>

callable like this:

<xsl:variable name="absnum">
  <xsl:call-template name="abs">
    <xsl:with-param name="input" select="some/number" />
  </xsl:call-template>
</xsl:variable>
Tomalak