xsl-list
[Top] [All Lists]

Re: [xsl] concat with unspecific length

2012-06-18 09:03:23
You might consider a function pad:

<xsl:function name="x:pad" as="xsd:string">
   <xsl:param name="s" as="xsd:string"/>
   <xsl:param name="l" as="xsd:integer"/>
   <xsl:choose>
     <xsl:when test="string-length($s) &gt;= $l">
         <xsl:sequence select="$s"/>
     </xsl:when>
     <xsl:otherwise>
         <xsl:sequence select="concat(x:pad($s, $l - 1),' ')"/>
     </xsl:otherwise>
   </xsl:choose>
</xsl:function>

which you can call like this

   x:pad( $Field1, 11 )

You might want to truncate when the string length exceeds the 2nd operand.

-W




On 18/06/2012, Syd Bauman <Syd_Bauman(_at_)brown(_dot_)edu> wrote:
Length various based on what? Until position 11, 16, or 27 of what?
From position 12 or 17 of what? (No field you show is > 10 chars, so
I'm guessing those positions are of the concatenation of all fields.)

Presuming
1) you can tuck the desired variable length from Field1 into a
   variable $F1len,
2) the other positions you want are from the concatenation of all 4
   strings,
3) we are in the template that matches the parent of the four <FieldN>
   elements, and
4) I understand what you're asking for (low probability),
then:

  <xsl:template match="FieldsParent">
    <xsl:variable name="F1len" select="6"/>
    <xsl:variable name="all" select="concat( Field1, Field2, Field3, Field4
)"/>
    <xsl:value-of select="concat(
      substring( $all, 1, $F1len ),
      ' ',
      substring( $all, 1, 11 ),
      ' ',
      substring( $all, 12 ),
      ' ',
      substring( $all, 1, 16 ),
      ' ',
      substring( $all, 17, 10 ),
      ' ',
      substring( $all, 1, 27 ),
      Field4
      )"/>
  </xsl:template>

should be pretty close.

I'm betting I don't want to know why you want to do this.


I have following xml bellow and want to concat together as here:
Field1 [from position 1, length varies] + " " [until position 11] +
Field2 [from position 12] + " " [until position 16]+ Field3 [from
position 17, length always 10] + " " [until position 27] + Field4
Input
<Field1>2000090691</Field1>
<Field2>0010</Field2>
<Field3>2000090690</Field3>
<Field4>0010</Field14>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>