Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - how do I match an replace text with XSL

 
Thread Tools Search this Thread
Old 07-18-2006, 01:59 PM   #1
Default how do I match an replace text with XSL


A simple XSL question from a newbie:

In an xml document which I transform via xsl into html output, I have
some text which I want to be suppressed.

The tags looks like this
<anchor_ref name="#B4">I. Introduction - page 4 </anchor_ref>
<anchor_ref name="#B4">II. Childhood - page 24 </anchor_ref>
<anchor_ref name="#B4">I. Later - page 42 </anchor_ref>

I want to define an xsl rule which gets rid of the page numbers which
make no sense in the html version.

I.e. anything fitting the pattern ' - page NN '
where NN is a single or double digit number should be replaced by nothing.

How would this XSL rule look?

A later complication will be that the word 'page' can also appear in
other languages, e.g. 'Seite 4', 'pagina 4' etc.


Alois Treindl
  Reply With Quote
Old 07-18-2006, 02:16 PM   #2
Dimitre Novatchev
 
Posts: n/a
Default Re: how do I match an replace text with XSL

Use the substring-before() function.

Cheers,
Dimitre Novatchev

"Alois Treindl" <my_real_firstname@my_real_lastname.com> wrote in message
news:e9iluo$3dp$...
>A simple XSL question from a newbie:
>
> In an xml document which I transform via xsl into html output, I have some
> text which I want to be suppressed.
>
> The tags looks like this
> <anchor_ref name="#B4">I. Introduction - page 4 </anchor_ref>
> <anchor_ref name="#B4">II. Childhood - page 24 </anchor_ref>
> <anchor_ref name="#B4">I. Later - page 42 </anchor_ref>
>
> I want to define an xsl rule which gets rid of the page numbers which make
> no sense in the html version.
>
> I.e. anything fitting the pattern ' - page NN '
> where NN is a single or double digit number should be replaced by nothing.
>
> How would this XSL rule look?
>
> A later complication will be that the word 'page' can also appear in other
> languages, e.g. 'Seite 4', 'pagina 4' etc.



  Reply With Quote
Old 07-18-2006, 02:22 PM   #3
Martin Honnen
 
Posts: n/a
Default Re: how do I match an replace text with XSL



Alois Treindl wrote:


> In an xml document which I transform via xsl into html output, I have
> some text which I want to be suppressed.
>
> The tags looks like this
> <anchor_ref name="#B4">I. Introduction - page 4 </anchor_ref>
> <anchor_ref name="#B4">II. Childhood - page 24 </anchor_ref>
> <anchor_ref name="#B4">I. Later - page 42 </anchor_ref>
>
> I want to define an xsl rule which gets rid of the page numbers which
> make no sense in the html version.
>
> I.e. anything fitting the pattern ' - page NN '
> where NN is a single or double digit number should be replaced by nothing.


XSLT 1.0/XPath 1.0 are not very powerful when it comes to string
manipulation, string matching, string replacement.
You could write an XSLT template
<xsl:template match="text()[contains(. 'page')]">
to match text nodes which contain the string 'page' but there are no
ways to do regular expression pattern matching for two digits behind 'page'.


So unless you can use XSLT/XPath 2.0 which has regular expression
support you have a lot of code to write in XSLT/XPath 1.0. It might help
to (re)use existing solutions for string replacement, see the replace
and tokenize solutions in EXSLT
<http://www.exslt.org/str/index.html>

--

Martin Honnen
http://JavaScript.FAQTs.com/
  Reply With Quote
Old 07-18-2006, 03:40 PM   #4
Alois Treindl
 
Posts: n/a
Default Re: how do I match an replace text with XSL

Martin Honnen wrote:
>
>
> Alois Treindl wrote:
>
>
>> In an xml document which I transform via xsl into html output, I have
>> some text which I want to be suppressed.
>>
>> The tags looks like this
>> <anchor_ref name="#B4">I. Introduction - page 4 </anchor_ref>
>> <anchor_ref name="#B4">II. Childhood - page 24 </anchor_ref>
>> <anchor_ref name="#B4">I. Later - page 42 </anchor_ref>
>>
>> I want to define an xsl rule which gets rid of the page numbers which
>> make no sense in the html version.
>>
>> I.e. anything fitting the pattern ' - page NN '
>> where NN is a single or double digit number should be replaced by
>> nothing.

>
> XSLT 1.0/XPath 1.0 are not very powerful when it comes to string
> manipulation, string matching, string replacement.
> You could write an XSLT template
> <xsl:template match="text()[contains(. 'page')]">
> to match text nodes which contain the string 'page' but there are no
> ways to do regular expression pattern matching for two digits behind
> 'page'.
>
>
> So unless you can use XSLT/XPath 2.0 which has regular expression
> support you have a lot of code to write in XSLT/XPath 1.0. It might help
> to (re)use existing solutions for string replacement, see the replace
> and tokenize solutions in EXSLT
> <http://www.exslt.org/str/index.html>
>



I use xsltproc, which says:
Using libxml 20510, libxslt 10033 and libexslt 722
xsltproc was compiled against libxml 20510, libxslt 10033 and libexslt 722
libxslt 10033 was compiled against libxml 20510
libexslt 722 was compiled against libxml 20510

I don't know whether this is XSLT/XPath 1.0 or 2.0.

If it is 2.0, I would of course be very happy to get explicit xsl rules.

So far, we have built a crutch and do the filtering with good old sed.
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump