xsl-list
[Top] [All Lists]

Re: [xsl] creating elements from semicolon delimited text

2010-03-03 14:41:49
Am 03.03.2010 um 21:07 schrieb Flanders, Charles E (US SSA):

I could use some help manipulating a paragraph of text delimited by a 
semicolon into a series of step elements. I need to take note/paragraph and 
create a series of steps. I'm using XSLT 2.0.

The XSL does not take advantage of XSLT 2.0. How about something like this for 
the core routine with the tokenize() function:

<xsl:template match="note[contains(para, 'Follow-on')]">
  <followon.maintsk>
    <xsl:for-each select="tokenize(para, '[:;]')">
      <xsl:choose>
        <xsl:when test="position() = 1">
          <title><xsl:value-of select="."/></title>
        </xsl:when>
        <xsl:otherwise>
          <step1><para>
            <xsl:value-of select="."/>
          </para></step1>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
  </followon.maintsk>
</xsl:template>

Of course, the changes in punctuation are not yet handled, but using replace() 
this would not be too difficult. I guess.

- Michael


This:

<note>
      <para>Follow-on maintenance: Stuff to do; 
More stuff do to; And then even more stuff to do.</para>
</note>

To this:

<followon.maintsk>
      <title>FOLLOW ON MAINTENANCE</title>
      <step1><para>Stuff to do.</para></step1>
      <step1><para>More stuff to do.</para></step1>
      <step1><para>And then even more stuff to do.</para><step1>
</followon.maintsk>

I've started with this. However this only captures the first item. And I 
realized later would NOT capture the last item, because it ends with a 
period, not a semicolon. One note, this is just a small part of much larger 
transform, hence the "mode."



<xsl:template match="note" mode="followon">
 <xsl:if test="(child::para) and (contains(child::para,'Follow-on'))">
   <followon.maintsk>
       <title><xsl:text>FOLLOW ON MAINTENANCE</xsl:text></title>
          <xsl:variable name="noFollow">
              <xsl:value-of select="substring-after(.,':')"/>
         </xsl:variable>
         <xsl:variable name="steptext">
            <xsl:value-of select="substring-before($noFollow,';')"/>
          </xsl:variable>
              <xsl:for-each select="$steptext">       
              <step1>
                <para>
                      <xsl:value-of select="$steptext"/><xsl:text>.</xsl:text>
              </para>
              </step1>
              </xsl:for-each>
   </followon.maintsk>
  </xsl:if>
</xsl:template>



Charles Flanders






--~------------------------------------------------------------------
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>