Subject: RE: [xsl] Escaping nodeset content From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Thu, 9 Mar 2006 17:47:36 -0000 |
Call out to an extension function that serializes the node-set as lexical XML, and pass the lexical XML back as a string. Saxon has such a function built-in: see saxon:serialize(). You can write your own serializer in XSLT if you must, but it's not much fun. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Kipp.Howard@xxxxxxxxxxxxxx [mailto:Kipp.Howard@xxxxxxxxxxxxxx] > Sent: 09 March 2006 17:41 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Escaping nodeset content > > 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 -> |
---|---|---|
[xsl] Escaping nodeset content, Kipp . Howard | Thread | RE: [xsl] Escaping nodeset content, Wendell Piez |
[xsl] Escaping nodeset content, Kipp . Howard | Date | RE: [xsl] plea for help..., Kipp . Howard |
Month |