Re: [xsl] regex and tab-delimited text

Subject: Re: [xsl] regex and tab-delimited text
From: Terry Ofner <tofner@xxxxxxxxxxx>
Date: Thu, 17 Jan 2008 17:19:27 -0500
Okay. So then my stylesheet needs to be adjusted somehow.

Here is what I am trying to do.

Snippet of xml input:
<test>
<question>	2	<stem>As used in the sentence below, what is the
denotation of the word <i>mutt</i>?</stem>
<display>&#8220;What is that mutt doing in our yard?&#8221; asked
Dad.</display>
<choices>
	A	animal
	B	dog
	C	creature
	D	pet
</choices>
</question>
</test>

I am trying to wrap each answer choice with the corresponding <choice-
x> element:

<choices>
	<choice-a>animal</choice-a>
	<choice-b>dog</choice-b>
	<choice-c>creature</choice-c>
	<choice-d>pet</choice-d>
</choices>

With my current stylesheet I am just trying to get choice A to work:

<xsl:stylesheet
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                  version="2.0">
            <xsl:output  method="xml"
                        indent="yes"/>

 <xsl:template match="@*|node()">
	<xsl:copy>
		<xsl:apply-templates select="@*|node()"/>
	</xsl:copy>
 </xsl:template>

 <xsl:template  match="/test/question/choices">
                <choice-a><xsl:copy-of select="replace(.,'\tA\t(.*?)
\r','$1')"/></choice-a>
 </xsl:template>
</xsl:stylesheet>


Current output:


<question> 2       <stem>As used in the sentence below, what is the
denotation of the word <i>mutt</i>?</stem>
      <display>What is that mutt doing in our yard? asked Dad.</
display>
<choice-a>
        A       animal
        B       dog
        C       creature
        D       pet</choice-a>
   </question>


Thanks in advance for any tips.


Terry

On Jan 17, 2008, at 3:48 PM, Jesper Tverskov wrote:

On 1/17/08, Terry Ofner wrote:
My question has to do with the fact that \t does not seem to work...

I should work. It is part of REGEX in XSLT building on REGEX in XML Schema: http://www.w3.org/TR/xmlschema-2/#regexs

Cheers,
Jesper Tverskov
http://www.xmlplease.com

Current Thread