 |
| 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
|
|
|
|

May 6th, 2009, 02:28 PM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 8
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
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 & and handle it but its printing out & 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
|
|

May 6th, 2009, 03:37 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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:
|
|
|

May 6th, 2009, 03:43 PM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 8
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
yes iam using <xsl:output method="text"/>
|
|

May 6th, 2009, 03:52 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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:
|
|
|

May 6th, 2009, 05:35 PM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 8
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
iam converting a xml file which is generated by normal text file write's through code. there iam changing all '&'s to & and writing into file.
ex:
<Rows>
<Row>
<Data>
<Value>example & 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
|
|

May 6th, 2009, 07:00 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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:
|
|
|

May 7th, 2009, 09:58 AM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 8
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 7th, 2009, 10:01 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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:
|
|
|

May 7th, 2009, 10:25 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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:
|
|
|

May 7th, 2009, 10:57 AM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 8
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
Thanks for your reply's ,i will look around for some ruby forums.
Last edited by vreddy; May 7th, 2009 at 11:00 AM..
|
|
 |