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 May 6th, 2009, 02:28 PM
Registered User
 
Join Date: May 2009
Posts: 8
Thanks: 6
Thanked 0 Times in 0 Posts
Default handling xslt ampersand (&) and other charecters like < , > etc

hi ,

i was trying to convert a xml file into fixed length text file using XSLT, iam having problems with ampersand.i could convert '&' to &amp; and handle it but its printing out &amp; instead of '&' into text file ,how can i handle this i.e write out & into text file.

i tried disable-output-escaping="yes" but its not working properly for me

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

Are you using xsl:output method="text"?
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
vreddy (May 7th, 2009)
 
Old May 6th, 2009, 03:43 PM
Registered User
 
Join Date: May 2009
Posts: 8
Thanks: 6
Thanked 0 Times in 0 Posts
Default

yes iam using <xsl:output method="text"/>
 
Old May 6th, 2009, 03:52 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In that case you will have to explain in more detail what you are doing. Please post a minimal example that demonstrates the problem, and tell us how you are running it.

If you are serializing using method="text" then there should never be any XML escaping in the output, so you're obviously doing something wrong and we need to see what.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
vreddy (May 7th, 2009)
 
Old May 6th, 2009, 05:35 PM
Registered User
 
Join Date: May 2009
Posts: 8
Thanks: 6
Thanked 0 Times in 0 Posts
Default

iam converting a xml file which is generated by normal text file write's through code. there iam changing all '&'s to &amp; and writing into file.

ex:
<Rows>
<Row>
<Data>
<Value>example &amp; something</Value>
</Data>
<Data>
<Value>this is test</Value>
</Data>
</Row>
<Row>
<Data>
<Value>tst23</Value>
</Data>
</Row>
<Rows>

xslt:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
<xsl:output method="text"/>
<xsl:template match="*">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>

<xsl:template match="/">
<xsl:apply-templates select="Rows"/>
</xsl:template>

<xsl:template match="Rows">
<xsl:apply-templates select="Row">
</xsl:apply-templates>
</xsl:template>

<xsl:template match="Row">
<xsl:apply-templates select="Data">
</xsl:apply-templates>
</xsl:template>

<xsl:template match = "Data">
<xsl:call-template name="manipulate-string">
<xsl:with-param name="value" select="Value"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="manipulate-string">
<xsl:param name="value"/>
<xsl:value-of select="$value"/>
</xsl:template>

</xsl:stylesheet>

iam doing something like above but with more string and other manipulations.am having problems with ampersand etc.

thank you
 
Old May 6th, 2009, 07:00 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

OK, thanks. The other half of the question was: how are you running the transformation? (What processor? Client side or server side? What API calls from your application?)
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
vreddy (May 7th, 2009)
 
Old May 7th, 2009, 09:58 AM
Registered User
 
Join Date: May 2009
Posts: 8
Thanks: 6
Thanked 0 Times in 0 Posts
Default

i use LIBXSLT and LIBXML in ruby code as shown below and its server side.

stylesheet_doc = LibXML::XML::Document.file('xsl_file.xsl')
stylesheet = LibXSLT::XSLT::Stylesheet.new(stylesheet_doc)

xml_doc = LibXML::XML::Document.file('temp_test.xml')
result = stylesheet.apply(xml_doc);

thanks
 
Old May 7th, 2009, 10:01 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Thanks. I'm afraid I don't know libxslt and ruby well enough to help.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
vreddy (May 7th, 2009)
 
Old May 7th, 2009, 10:25 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I am also not familiar with libXML and libXSLT and Ruby but the API docs suggest that the result of the apply method is an libXML XML document. I don't know what they do in the case of output method="text" but for instance the Mozilla XSLT API, when output method="text", gives you the text as the text contents of the root element of the result document so with your libXML you might want to check whether
Code:
stylesheet_doc = LibXML::XML::Document.file('xsl_file.xsl')
 stylesheet = LibXSLT::XSLT::Stylesheet.new(stylesheet_doc)

xml_doc = LibXML::XML::Document.file('temp_test.xml')
result = stylesheet.apply(xml_doc);
text = result.root.content
gives you the plain text you are looking for. That is just a guess however, you might have better chances finding someone with knowledge of the those APIs on a Ruby list (or a list dedicated to those libraries).
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
vreddy (May 7th, 2009)
 
Old May 7th, 2009, 10:57 AM
Registered User
 
Join Date: May 2009
Posts: 8
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Thanks for your reply's ,i will look around for some ruby forums.

Last edited by vreddy; May 7th, 2009 at 11:00 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
.Net2 xslt does not like the &lt; "<" - &gt; ">" ismailc XSLT 4 October 11th, 2008 04:40 AM
Ch 8: <asp:image> inside <a> & ext.CSS (pg. 274) epc BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 July 12th, 2008 04:37 AM
> 4000 Charecters mamasagarika Oracle ASP 1 August 5th, 2005 04:12 AM
<style> tags in a <body> vs. <div> bcat BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 27th, 2005 08:50 AM
XML from a DB recordset (removal of &lt;&gt;) Thodoris XML 3 July 13th, 2004 12:28 AM





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