473,408 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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.
Jul 18 '06 #1
3 5125
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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rainer Herbst | last post by:
Hi *, please consider the following problem: I have a XML document which includes some html elements. I want to replace only the <div> element: I specified two templates, one matches...
4
by: aliensite | last post by:
My code is too greedy, how can it be fixed? Here is my code: Desired output - First:,Second:,Third: <br> <script type="text/javascript"> var regEx = /*?:/g; var html = "<br>First:ratio<br...
2
by: GreggTB | last post by:
Hello, I'm trying to perform a very simple validation of user input. I want to verify that the user entered a six-digit string consisting entirely of numbers. So anything from 000000 to 999999 is...
5
by: JackRazz | last post by:
Anyone know the regular expression to match a blank line where the byte sequence is "0D 0A 0D 0A" ive tried "\r\n\r\n+", "^$+" "\n\r" with no success. Any Ideas? Thanks - JackRazz This is...
17
by: Randy Webb | last post by:
I know that the /g flag will match all occurrences. Is there a way, with a Regular Expression, to match all occurrences *except* the last one? pattern = /df/g; var myString = "asdfasdfasdfasdf";...
1
by: justin.mayes | last post by:
hello all - An example. You have a regular expression to locate certain html tags. "(<)" This will find every instance of a "<" character that is not followed by a letter. The match will...
3
by: skneife | last post by:
Hi, I have an input string : <NEW>g04 8/1 0<catset>pub=g04</catset> and I use this regex expresssion to match from <NEWto </catset>, I wrote: <NEW>.+?</catsetbut it doesn't work, no match !...
14
by: Andy B | last post by:
I need to create a regular expression that will match a 5 digit number, a space and then anything up to but not including the next closing html tag. Here is an example: <startTag>55555 any...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.