Subject: Re: [xsl] child nodes and regex From: Mike Sokolov <sokolov@xxxxxxxxxxxx> Date: Thu, 18 Jun 2009 17:12:57 -0400 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] child nodes and regex, Terry Ofner | Thread | [xsl] [FO] page-sequence/@initial-p, Florent Georges |
[xsl] child nodes and regex, Terry Ofner | Date | Re: [xsl] Entity escaping/translati, Dan Vint |
Month |