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 12th, 2008, 10:28 AM
Authorized User
 
Join Date: May 2008
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anboss
Default to treat xml as string

i need help with the following xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
        <xsl:variable name="request">
            <xsl:value-of disable-output-escaping="yes" select="string('<![CDATA[')"/>
            <xsl:copy-of select="."/>
            <xsl:value-of disable-output-escaping="yes" select="string(']]>')"/>
        </xsl:variable>
    <xsl:value-of select="$request"/>
    </xsl:template>
</xsl:stylesheet>

if i give the following as input to this xsl:

<?xml version="1.0" encoding="UTF-8"?>
<g>
    <h>
        <a>value1</a>
        <b>value2</b>
    </h>
</g>

instead of getting the xml message as such within the CDATA tags, i get the following:

<![CDATA[value1value2]]>

my idea is to treat this xml as a string and pass the xml to a compression function. which will return a compressed string encoded in base 64 format.

<xsl:variable name="shortVersion" select="dp:deflate($request)"/>

now instead of the xml request only the texts present in the xml is going as input to the function.

how can i retrieve the xml as such?

 
Old July 12th, 2008, 10:43 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Instead of

<xsl:value-of select="$request"/>

do

<xsl:copy-of select="$request"/>

You can't rely on disable-output-escaping working when writing to a variable. It's an instruction to the serializer, and only takes effect if the system decides to serialize the tree. I can't see why you want the CDATA section anyway - the purpose of CDATA is to say that things like <a>..</a> which look like XML markup are not to be treated as XML markup, whereas it sounds as if you actually do want them treated as markup.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 12th, 2008, 11:28 AM
Authorized User
 
Join Date: May 2008
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anboss
Default

yeah ther is a serializer function available in the appliance.. thanks KAY

 
Old July 12th, 2008, 04:03 PM
Registered User
 
Join Date: May 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm not sure if I'm experiencing the same problem but any time I try to use <xsl:value-of or copy-of or param and try to include a < character in the select string I get an XSLT compile error: {"'<', hexadecimal value 0x3C, is an invalid attribute character. Line 6, position 26."}.

Example: <xsl:value-of select="'<'"/>

The < shows up in my editor as opening a new XML tag no matter how I try to embed it in quotes, functions etc. I am admittedly fairly new to XSL but I haven't been able to find any specific examples of using the < in a string until the above post. Any help is appreciated.
Thanks,
Jeff
 
Old July 13th, 2008, 03:14 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>any time I try to use <xsl:value-of or copy-of or param and try to include a < character in the select string I get an XSLT compile error

No, you get an XML parsing error - the XSLT processor doesn't even get to see the stylesheet if it's not well-formed XML. In any XML document, a "<" character in attribute or element content needs to be escaped as &lt;

I didn't spot this error in the original post.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 13th, 2008, 10:45 AM
Registered User
 
Join Date: May 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much. I see now where I was confused.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating XML doc ; writing string(xml format) into KamalRaturi XML 5 May 28th, 2008 05:51 AM
convert string to xml prafullaborade XML 3 May 21st, 2008 06:56 AM
String to XML rprinfo ASP.NET 1.0 and 1.1 Basics 1 April 20th, 2007 03:48 AM
My stylesheet treat!! freezotic BOOK: Beginning Java 2 1 March 26th, 2004 04:30 PM
Load Xml From String ffbalota J2EE 0 January 24th, 2004 06:30 PM





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