Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 24th, 2006, 08:40 AM
Authorized User
 
Join Date: Jul 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to use replace function() xslt 2.0

Hi all,
I want to use replace function in xslt ; but it doesn't seem to work.

Can anyone give me an example:

say I want to replace all the occurences of & in xml1 with and in xml2 using stylesheet.

Thx!!!


 
Old July 24th, 2006, 08:45 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

There are examples in the spec.

Please show some simple code you have written and then I can see where you have gone wrong.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 24th, 2006, 09:05 AM
Authorized User
 
Join Date: Jul 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm not at all sure this is the right way I serached for the replace function used in xslt 2.0 but did not find any which talked abt using replace('text','t','a') kind of examples.

Plz give an example which would help me in understanding what you are saying....that would be of great help!!!!!!!!!

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test1.xsl"?>
<record>
<textDescription>Levels in the levels node are L1 &amp; L2 &amp; </textDescription>
</record>


XSLT:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:marc="http://www.loc.gov/MARC21/slim">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
    <xsl:for-each select="record">
<xsl:for-each select="textDescription">
<xsl:value-of select=" replace(current(),'&amp;','and')"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

 
Old July 24th, 2006, 09:39 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The spec, together with examples, is at

http://www.w3.org/TR/xpath-functions/#func-replace

But your code works fine for me using Saxon: it produces the output

<?xml version="1.0" encoding="UTF-8"?>Levels in the levels node are L1 and L2 and

Is that the output you wanted? Are you seeing something different?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 24th, 2006, 11:31 AM
Authorized User
 
Join Date: Jul 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

'replace' is not a valid XSLT or XPath function

This is the error when I look for the output in the browser which is IE OR look at the output in altova xml spy editor.

I don't know why does it give me an error.

Thanks!

 
Old July 24th, 2006, 12:37 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You're running your code in an XSLT 1.0 processor. As I think you are aware, this function needs XSLT 2.0.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 24th, 2006, 12:55 PM
Authorized User
 
Join Date: Jul 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Since this xslt proceessor thing came up these are my concerns when I'm working with my present stuff:

1. I have worked with maximum 10,000 - 15,000 lines of code
xml -> xsl ->xsl/html page using xml spy editor or any browser and it works fine.

2. Now I have a xml file for which I have written stylesheet which has close to 2 million lines of code and has 15,000 records I don't know which processor to use so that I can see the output xml file.
my xml spy editor says ran out of memory when I try to open the file .

3. which editor/ processor do I use so that I can get my ouput xml and my replace() function works fine .



 
Old July 24th, 2006, 01:17 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The most commonly used XSLT 2.0 processor is my own Saxon product, see http://saxon.sf.net/

You can reasonably expect to handle input documents up to 100Mb provided you can allocate 512Mb of main memory.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 24th, 2006, 02:39 PM
Authorized User
 
Join Date: Jul 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I downloaded saxon version 8.3 ; I have java 1.5 on my system.

But after downloading saxon ; I did not find any installation instructions to make this work and actually start using the xslt processor.

Where can I find the installation instructions and make it actually work.

May be I have to ask my Company to buy a license of your product but before doing that I need to get this working so that I can see for myself how things work using this product.

I know this may seem dumb but I did not find any instructions or read me file to actually follow them.....

 
Old July 24th, 2006, 03:37 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I assume you mean Saxon 8.7.3 rather than 8.3.

All the documentation including instructions for getting started is available online at http://www.saxonica.com/documentation/index/intro.html

The file doc/index.html in the unzipped software contains pointers to this site and to other documentation resources. Note in particular that there's an extra download file saxon-resources.zip that contains documentation, source code, and sample applications.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
xslt replace function rajesh_css XSLT 7 October 30th, 2008 08:39 PM
replace function keyvanjan Classic ASP Basics 3 May 15th, 2006 12:57 AM
Character replace function? echovue Access 2 December 21st, 2004 01:53 PM
replace function Adam H-W Classic ASP Basics 3 September 20th, 2004 09:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.