xsl-list
[Top] [All Lists]

[xsl] child nodes and regex

2009-06-18 17:05:08
I am having trouble outputting child nodes as part of regex
matching-substring.

XML input contains the following:

<question>
<text><p> 32 What is the most effective way to revise sentence 1?</p></text>
<choice> F insert a comma after <i>American</i></choice>
<choice> G use dashes . . . was Samuel Clemens</choice>
<choice> H insert a period after Clemens</choice>
<choice> J use quotation marks. . . was Samuel Clemens</choice>
</question>

I am attempting to use the capital letter following each <choice> opening
element to create the following elements:

<choice-f>insert a comma after <i>American</i></choice-f>
<choice-g>use dashes to set off the clause whose real name was Samuel
Clemens</choice-g>
etc.

Here is the relevant template from the 2.0 stylesheet:

<xsl:template match="choice">
   <xsl:analyze-string select="." regex="^ ?([A-J]) ?(.*)">
     <xsl:matching-substring>
        <xsl:variable name="choiceLetter">
          <xsl:value-of select="lower-case(regex-group(1))"/></xsl:variable>
            <xsl:element name="choice-{$choiceLetter}">
               <xsl:value-of select="regex-group(2)"/>
            </xsl:element>
      </xsl:matching-substring>
    </xsl:analyze-string>
</xsl:template>

This works up to a point. The only problem is that it strips out the <i>
elements, leaving the text in place. Notice in this output that <i> elements
have been removed around American:

<question><text><p> 32 What is the most effective way to revise sentence
1?</p></text>
   <choices>
       <choice-f>insert a comma after American</choice-f>
       <choice-g>use dashes . . . was Samuel Clemens</choice-g>
       <choice-h>insert a period after Clemens</choice-h>
       <choice-j>use quotation . . . was Samuel Clemens</choice-j>
   </choices>
       . . .
</question>

I seem to recall matching choice/text() in prior cases. But I have not
been able to get that to work properly in this current situation.

Any suggestions would be most appreciated.

Terry Ofner



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