By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,916 Members | 1,068 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,916 IT Pros & Developers. It's quick & easy.

how do I match an replace text with XSL

P: n/a
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.
Jul 18 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Use the substring-before() function.

Cheers,
Dimitre Novatchev

"Alois Treindl" <my_real_firstname@my_real_lastname.comwrote in message
news:e9**********@atlas.ip-plus.net...
>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.

Jul 18 '06 #2

P: n/a


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/
Jul 18 '06 #3

P: n/a
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.
Jul 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.