Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 27th, 2007, 05:24 PM
Registered User
 
Join Date: Nov 2007
Location: Austin, Texas, USA.
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
Reply With Quote
  #2 (permalink)  
Old November 27th, 2007, 05:54 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Reply With Quote
  #3 (permalink)  
Old November 27th, 2007, 08:41 PM
Registered User
 
Join Date: Nov 2007
Location: Austin, Texas, USA.
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
Reply With Quote
  #4 (permalink)  
Old November 28th, 2007, 06:01 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Reply With Quote
  #5 (permalink)  
Old November 28th, 2007, 09:46 PM
Registered User
 
Join Date: Nov 2007
Location: Austin, Texas, USA.
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>
Reply With Quote
  #6 (permalink)  
Old November 29th, 2007, 04:56 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
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 -/
Reply With Quote
  #7 (permalink)  
Old November 29th, 2007, 10:48 PM
Registered User
 
Join Date: Nov 2007
Location: Austin, Texas, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Sam. I will look at the below functions.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:53 PM.


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