An example of its use
(I used #133 instead of hellip... it comes out the same if you serialise as html, but it saves me from having to add Entity declarations to teh XSLT)
Main Topics
Browse All TopicsHello,
I have created a template that matches all text nodes in my document (match="text()"). I want this template to perform some search and replace on the text. For example, I want to replace all occurences of " --" with " –" and all occurences of "..." with "…" and so on. What is the easiest way of doing this?
Thank you.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks. But If I want to replace multiple things, I will have to call that template inside the parameter of another template call, which is also inside a parameter of another template call. Can this be somehow simplified?
I would really like to use XSLT 2.0 but I can't find a library that I could use from PHP.
Maybe I could do some processing in PHP and some processing in XSLT?
<terms>
<term find="..." replace="…"/>
<term find="--" replace=" –"/>
</terms>
now, find a way to automate reading that XML (using document() eg.
and for each term take the result of the previous step and make another replace,
this will give you much nicer code than teh nested call-templates or stuffing each result in a variable
It will be more flexible if you need to ad a term for replacement
Hello. Thanks for your help.
I tried this:
<xsl:variable name="replace-rules" xmlns:r="http://ondra.cifk
<r:rule>
<r:find> ---</r:find>
<r:replace> —</r:r
</r:rule>
<r:rule>
<r:find>---</r:find>
<r:replace>—</r:replace
</r:rule>
<r:rule>
<r:find> --</r:find>
<r:replace> –</r:r
</r:rule>
<r:rule>
<r:find>--</r:find>
<r:replace>–</r:replace
</r:rule>
<r:rule>
<r:find>...</r:find>
<r:replace>…</r:replac
</r:rule>
</xsl:variable>
Then I want to for-each through this variable:
<xsl:template match="text()">
<xsl:for-each select="$replace-rules/r:r
<xsl:value-of select="r:find" />
<xsl:value-of select="r:replace" />
</xsl:for-each>
</xsl:template>
And I get this error:
Chyba pYi kontrole typu výrazu 'FilterParentPath(variable
(Error checking expression type)
What's going on?
Sorry to say, but my slovak language knowledge is a bit "not helping" for understanding the error message :-)
Anyway, what you are trying to do will only work in XSLT2 or with a nodeset extension in XSLT1.
Each processor has its own nodeset extension, so you will need to tell me which processor you are using,
I usually put that as plain XML in my XSLT and use document('')/r:rule to address them
(document('') points inside the XSLT
Your for-each will not work because you can not pass the result from the previous step in,
remeber that variables don't vary in XSLT
so you will need recursion
please note that you need an entity declaration in your stylesheet to be able to use the entities
I now have to go, but I can help you getting started later
Business Accounts
Answer for Membership
by: GertonePosted on 2009-10-19 at 12:17:56ID: 25608096
Hey, XSLT (and specially XSLT1) is not really meant for advanced text processing
Here is a template that calls itself (recursively) that replaces a string with another string in a text() node
Select allOpen in new window