Regular Expression using XSLT

Here should go questions about transforming XML with XSLT and FOP.
ankitbhurat
Posts: 3
Joined: Mon Jul 23, 2007 3:59 pm

Regular Expression using XSLT

Post by ankitbhurat »

Hello every1

I am using ASP.NET 1.1 ,

I have a problem task in which i have to search employees whose first names start with 'A' to 'G'.

e.g.

ABC
CF
Ef
FF
GH

I have data in my XML.

Any solution hint will also do,

Many thanks in advance.
Ankit
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

Hello,

The regular expression for names that start with A - G is ^[A-G]\w+ but using it in the XSLT stylesheet depends on the structure of the input XML document. For example if you must process only elements with employees having names starting with A - G in an XML file like:

Code: Select all


<all>
<emp id="emp01">
<first_name>FirstName</first_name>
<last_name>LastName</last_name>
</emp>
...
</all>
then you can use in the XSLT stylesheet:

Code: Select all


    <xsl:template match="emp[matches(first_name, '^[A-G]\w+')]">
...
</xsl:template>
Regards,
Sorin
Last edited by sorin_ristache on Tue Jul 24, 2007 1:32 pm, edited 1 time in total.
ankitbhurat
Posts: 3
Joined: Mon Jul 23, 2007 3:59 pm

Thanks, will this work for 1.0 alos ?

Post by ankitbhurat »

Thanks Sorin

for ur inputs ..


I am rather new to XSLT... Just wanted to know if this wil work for version 1.0 also ?.

Many THanks

sorin wrote:Hello,

The regular expression for names that start with A - G is [A-G]\w+ but using it in the XSLT stylesheet depends on the structure of the input XML document. For example if you must process only elements with employees having names starting with A - G in an XML file like:

Code: Select all


<all>
<emp id="emp01">
<first_name>FirstName</first_name>
<last_name>LastName</last_name>
</emp>
...
</all>
then you can use in the XSLT stylesheet:

Code: Select all


    <xsl:template match="emp[matches(first_name, '^[A-G]\w+')]">
...
</xsl:template>
Regards,
Sorin
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

In XSLT 1.0 you can use for example the regular expression module of the EXSLT library.


Regards,
Sorin
Last edited by sorin_ristache on Tue Jul 24, 2007 2:39 pm, edited 1 time in total.
ankitbhurat
Posts: 3
Joined: Mon Jul 23, 2007 3:59 pm

Thanks

Post by ankitbhurat »

Thanks,

I have downloaded the ZIP file. Wil let you know if I face any problem.

Please selected the option "Notify me when a reply is posted", so that you are keep informed.

Ankit
sorin wrote:In XSLT 1.0 you can use for example the regular expression part of the EXSLT library.


Regards,
Sorin
Post Reply