Re: [xsl] Pattern Substring

Subject: Re: [xsl] Pattern Substring
From: Senthilukvelaan <skumaravelan@xxxxxxxxxxxxxx>
Date: Wed, 3 Mar 2010 11:37:29 -0800
Hi,
Yes, the Option Number might not start with 55 in some cases, I would
like to handle them as well. I do not have option of
moving to XSLT 2.0 at this time.
Please suggest me ,how this can be done in XSLT 1.0.

Thanks,
Senthil

On Wed, Mar 3, 2010 at 9:02 AM, Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> wrote:
> Senthilukvelaan,
>
> The processor is giving you exactly what you have requested. In effect, you
> have defined your optionNumber as the whitespace-normalized value of the
> nine-character string starting with the first appearance of '055' in your
> element content.
>
> But it sounds like this isn't what you want, since some of your option
> numbers don't start with '055', but have prefixes.
>
> The solution depends on the definition of the option number, including the
> prefix. How do you recognize it?
>
> Given that specification, this will almost certainly be easier to implement
> in XSLT 2.0 using a regular expression.
>
> Cheers,
> Wendell
>
> At 01:37 AM 3/3/2010, you wrote:
>>
>> Hi,
>> My input :
>> <OPTIONS >Text1  X055-0001 Text1 Textx2</OPTIONS>
>> <OPTIONS >Text1 055-0002 Text1 Text3</OPTIONS>
>>
>> xslt
>>  <xsl:template match="OPTIONS">
>>  <xsl:variable name="index"
>>  select="string-length(substring-before(.,'055'))"/>
>>    <xsl:element name="OPTION">
>>  <xsl:attribute name="optionNumber"><xsl:value-of
>>  select="normalize-space(substring(.,$index,9))"/></xsl:attribute>
>>        <xsl:apply-templates/>
>>    </xsl:element>
>>  </xsl:template>
>>
>> My desired output
>> <OPTION optionNumber=' X055-0001'>Text1 X055-0001 Text1</OPTION>
>>  <OPTION  optionNumber='055-0001'>Text1 055-0001 Text1</OPTION>
>>
>> But My actual output using the code
>> <OPTION optionNumber='055-0001'>Text1 X055-0001 Text1</OPTION>
>>  <OPTION  optionNumber='055-0002'>Text1 055-0001 Text1</OPTION>
>>
>>
>> I am trying to create a option Number attribute from the Options
>> value. The <OPTIONS> value contains the optionnumber value prefix and
>> suffix by some text value.
>>
>> I am not sure, How to do this?
>>
>> Please help.
>>
>>
>> On Tue, Mar 2, 2010 at 10:17 PM, Ramesh, Marimuthu <M.Ramesh@xxxxxxxxxxx>
>> wrote:
>> > Hi,
>> >
>> > Your requirement is bit unclear. Your below code gives the output as
>> > below:
>> >
>> > <OPTION optionNumber="X055-0001">Text1 X055-0001 Text1 Textx2</OPTION>
>> >
>> > <OPTION optionNumber="055-0002">Text1 055-0002 Text1 Text3</OPTION>
>> >
>> > But your desired output below does not have any OPTION element, and also
>> > the text inside the elements differ.
>> >
>> > <OPTIONS optionNumber='X055-0001'>Text1 X055-0001 Text1</OPTIONS>
>> > <OPTIONS optionNumber='055-0001'>Text1 055-0001 Text1</OPTIONS>
>> >
>> >> Using the template I am able to get the second node correctly .
>> >
>> > Do you mean the output by the above line.
>> >
>> > Make the requirement clear.
>> >
>> > Regards,
>> > Rummy
>> >
>> > -----Original Message-----
>> > From: Senthilukvelaan [mailto:skumaravelan@xxxxxxxxxxxxxx]
>> > Sent: Wednesday, March 03, 2010 11:02 AM
>> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>> > Subject: [xsl] Pattern Substring
>> >
>> > Hi ,
>> > I have xml like below and I want to do pattern match and get option
>> > numbers which is always space delimited. Using the template I am able
>> > to get the second node correctly .
>> > But in the First element, am somehow missing the "X".
>> >
>> > Input:
>> >
>> > <OPTIONS >Text1 X055-0001 Text1 Textx2</OPTIONS>
>> > <OPTIONS >Text1 055-0002 Text1 Text3</OPTIONS>
>> >
>> > my xslt
>> >
>> >  <xsl:template match="OPTIONS">
>> >  <xsl:variable name="index"
>> > select="string-length(substring-before(.,'055'))"/>
>> >    <xsl:element name="OPTION">
>> >  <xsl:attribute name="optionNumber"><xsl:value-of
>> > select="normalize-space(substring(.,$index,9))"/></xsl:attribute>
>> >        <xsl:apply-templates/>
>> >    </xsl:element>
>> >  </xsl:template>
>> >
>> > desired output:
>> > <OPTIONS optionNumber=' X055-0001'>Text1 X055-0001 Text1</OPTIONS>
>> > <OPTIONS  optionNumber='055-0001'>Text1 055-0001 Text1</OPTIONS>
>
>
> ======================================================================
> Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
> Mulberry Technologies, Inc.                http://www.mulberrytech.com
> 17 West Jefferson Street                    Direct Phone: 301/315-9635
> Suite 207                                          Phone: 301/315-9631
> Rockville, MD  20850                                 Fax: 301/315-8285
> ----------------------------------------------------------------------
>  Mulberry Technologies: A Consultancy Specializing in SGML and XML
> ======================================================================

Current Thread