Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML 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 November 27th, 2007, 05:24 PM
Registered User
 
Join Date: Nov 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to output the entire content to a string

Hello,
I am using XSLT 2.0 processor.
I am trying to output the entire result tree (including the XML data input, and the XSL fixed data) to a string, so I can parse and count the number of times a particular character (used in the XSL string) has occurred in the result tree. This is needed for me in completing my transforms and creating the final output file.

If I use <xsl:value-of select="string(/)"/>, the resulting string contains only XML data elements as parsed in the XSL transforms, and does not contain any fixed XSL strings associated with the XML elements in the final output.

One way I can think of is to create the interim output, load the interim output as an input file, and then search the data, and create the final output file. But, it seems very round about and was curious to see if there is an easier way to do this.

Pls help,

Thanks,
Sunny
 
Old November 27th, 2007, 05:54 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

People usually control the final serialization of the result tree from the calling (e.g. Java) application. Saxon does however allow you to invoke serialization from within XSLT using the saxon:serialize() extension function.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 27th, 2007, 08:41 PM
Registered User
 
Join Date: Nov 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael,
Would you pls point me to any sample codes showing the usage for the serialize () function?
I am currently using Saxon 8.9.0.4 version, and do I need to upgrade to 9.0 for using this function?

Thanks,
Sunny
 
Old November 28th, 2007, 06:01 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The documentation is at

http://www.saxonica.com/documentatio...serialize.html

and the function has been in the product for some time.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 28th, 2007, 09:46 PM
Registered User
 
Join Date: Nov 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Michael,
Thanks for the pointer.
I am getting compilation error on the usage of the string literal expression in the serialize function.

My stylesheet structure is as shown below, and I am trying to serialize the output to a string so that, I can later parse and count the number of a occurances of a particular character in the output. To test it out, I am sending the value of $result string in the last template match section.

It gives me an error on the param name declaration line for "result" parameter declaration as "xsl:param" must not contain the '<' character error.

I am not sure what I am doing wrong, and how I can get the interim output of my xsl transform into a string that I can later use in the stylesheet.

Pls help.

Thanks!
Sunny
**********************

<xsl:param name ="result" select="saxon:serialize(node(),'<xsl:apply-templates select="main" />')" />

<xsl:template match="main">
<xsl:apply-templates select="./A" />
<xsl:apply-templates select="./B" />
<xsl:apply-templates select="./C" />
<xsl:apply-templates select="./D" />
</xsl:template>

<xsl:template match="A">
</xsl:template>

<xsl:template match="B">
</xsl:template>

<xsl:template match="C">
</xsl:template>

<xsl:template match="D">
<xsl:value-of select="$result" />
</xsl:template>
</xsl:stylesheet>
 
Old November 29th, 2007, 04:56 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

saxon:serialize takes the first parameter (a node or node tree) and converts it to a string (basically) using the settings specified in the second parameter, which should either be a string ('xml', 'html' etc) or a <xsl:output> node (not a string).

If you are actually wanting to run a transformation then you need to look att he saxon:compile-stylesheet() and saxon:transform() functions.

/- Sam Judson : Wrox Technical Editor -/
 
Old November 29th, 2007, 10:48 PM
Registered User
 
Join Date: Nov 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Sam. I will look at the below functions.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Output loop data to a string iloveoatmeal Classic ASP Basics 2 December 22nd, 2005 08:28 PM
how to output non-well formed string harag XSLT 5 November 10th, 2003 11:47 PM
How to search entire DB[?] Blaise SQL Server 2000 7 June 11th, 2003 09:41 AM





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