Subject: [xsl] Escaping nodeset content From: Kipp.Howard@xxxxxxxxxxxxxx Date: Thu, 9 Mar 2006 09:40:31 -0800 |
I have an application where I need to convert, with an xsl transform, some nodeset to escaped text (i.e., <abc/> => "<abc/>"). Attached you will find some tests cases with a transform that kind-of does what I want, but it is not escaping the result. Is there anyway to do what I want within an xsl transform? I know this is a brain-dead way of processing XML, but the guy that designed the message I'm trying to generate didn't know much about including XML within another XML document (using namespaces and such) so he just put it in as text :(. We are planning on redesigning this at the end of this year but for now, we have to work within this design. Thanks for any help. I tried to send these as attachments but the message was rejected with: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>: ezmlm-reject: fatal: Sorry, I don't accept messages of MIME Content-Type 'multipart/mixed' (#5.2.3) Here is the content of the files I tried to send: commonTools.xsl: <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" encoding="utf-8"/> <xsl:template match="commonToolsData"> <commonToolsTest> <xsl:apply-templates /> </commonToolsTest> </xsl:template> <xsl:template match="nodeSetToConvert"> <textFromNodeSet> <!-- Not sure how to copy the output as text --> <xsl:copy-of select="*"/> </textFromNodeSet> </xsl:template> <!-- Identity --> <!-- Whenever you match any node or any attribute --> <xsl:template match="node()|@*"> <!-- Copy the current node --> <xsl:copy> <!-- Including any attributes it has and any child nodes --> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> commonTools.xml: <?xml version="1.0" encoding="utf-8" ?> <commonToolsData> <convertedNodesetTest> <convertionTest> <nodeSetToConvert><result>&</result></nodeSetToConvert> <expectedText><result>&amp;</result></expectedText> </convertionTest> <convertionTest> <nodeSetToConvert><result><</result></nodeSetToConvert> <expectedText><result>&lt;</result></expectedText> </convertionTest> <convertionTest> <nodeSetToConvert><result>></result></nodeSetToConvert> <expectedText><result>&gt;</result></expectedText> </convertionTest> <convertionTest> <nodeSetToConvert><result>'</result></nodeSetToConvert> <expectedText><result>'</result></expectedText> </convertionTest> <convertionTest> <nodeSetToConvert><result>"</result></nodeSetToConvert> <expectedText><result>"</result></expectedText> </convertionTest> <convertionTest> <nodeSetToConvert><result dq="double">data</result></nodeSetToConvert> <expectedText><result dq="double">data</result></expectedText> </convertionTest> <convertionTest> <nodeSetToConvert><result sq='double'>data</result></nodeSetToConvert> <!-- Single quotes get automatically converted to double quotes --> <expectedText><result sq="double">data</result></expectedText> </convertionTest> <convertionTest> <nodeSetToConvert> <top double="two" single='one'> <amp>&</amp> <greater>></greater> <less><</less> <apos>'</apos> <quot>"</quot> </top> </nodeSetToConvert> <expectedText><top double="two" single="one"><amp>&amp;</amp><greater>&am p;gt;</greater><less>&lt;</less><apos>'< /apos><quot>"</quot></top></expectedText> </convertionTest> </convertedNodesetTest> </commonToolsData>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: RE: RE: RE: [xsl] FW: XSL proc, Cave, Neil | Thread | RE: [xsl] Escaping nodeset content, Michael Kay |
RE: [xsl] plea for help..., Florent Georges | Date | RE: [xsl] Escaping nodeset content, Michael Kay |
Month |