michaelloveusa Posted May 7, 2012 Posted May 7, 2012 So, I solved my previous problem of getting an xml encoded string out into an xml structure. Now I have to get a structure out into an escaped string (see the "manualAllocXML" element below): <s:element name="AllocatePayment"><s:complexType><s:sequence><s:element minOccurs="0" maxOccurs="1" name="securityToken" type="s:string" /><s:element minOccurs="1" maxOccurs="1" name="effPayDate" type="s:dateTime" /><s:element minOccurs="0" maxOccurs="1" name="manualAllocXml" type="s:string" /></s:sequence></s:complexType></s:element> I have the manualAllocXML in normal format as such: <manualalloc xmlns:xsi="http://www.w3.org/20...Schema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" resultdescr="test" resultstatus="0" xmlns="http://www.replaceme...mas/ManualAlloc"> <revobjs> <revobj dirtyreadchecksum="57" id="154917"/> <taxbills> <taxbill dirtyreadchecksum="57" id="1484553" revobjid="154917"/> </taxbills> </revobjs> <allocs> <alloc amount="5805.73" revobjid="271968" rolltype="1000002" revenuesource="290019" cd="0" subcd="0" taxbillid="6714081"/> </allocs></manualalloc> but I need to get it into an xml encoded string as such: <manualalloc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" resultdescr="test" resultstatus="0" xmlns="http://www.replaceme.com/schemas/ManualAlloc"><revobjs><revobj dirtyreadchecksum="57" id="154917"/><taxbills><taxbill dirtyreadchecksum="57" id="1484553" revobjid="154917"/></taxbills></revobjs><allocs><alloc amount="5805.73" revobjid="271968" rolltype="1000002" revenuesource="290019" cd="0" subcd="0" taxbillid="6714081"/></allocs></manualalloc> Is there a clever way to do this? Thanks, Mike
Martin Honnen Posted May 7, 2012 Posted May 7, 2012 See http://lenzconsulting.com/xml-to-string/ for a pure XSLT solution or if you use a certain XSLT processor like Saxon use a supported extension function like http://www.saxonica.com/documentation/extensions/functions/serialize.xml.
michaelloveusa Posted May 7, 2012 Author Posted May 7, 2012 Hi Martin - I checked out the xml-to-string xsl file, but I don't see how to set up the input parameter. The examples were not very helpful. Can you provide more guidance? Thanks! Mike
Martin Honnen Posted May 8, 2012 Posted May 8, 2012 http://p2p.wrox.com/xslt/84026-setting-xml-cdata.html#post273275 has some sample code of applying the code I linked to.
michaelloveusa Posted May 9, 2012 Author Posted May 9, 2012 Still struggling with this. Here is what I have in my xsl: <xsl:param name="ManualAlloc"/> <xsl:import href="http://lenzconsulting.com/xml-to-string/xml-to-string.xsl"/> <xsl:output method="xml" cdata-section-elements="ManualAlloc"/> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="ManualAlloc"> <xsl:copy> <xsl:call-template name="xml-to-string"> <xsl:with-param name="node-set" select="node()"/> </xsl:call-template> </xsl:copy> </xsl:template> ManualAlloc is the param I want converted to a string (minus the CDATA designation). I am getting back exactly what I am putting in. Ideas? Mike
Martin Honnen Posted May 10, 2012 Posted May 10, 2012 Well what kind of parameter is that, are you passing in a node-set? Or which type does that parameter have?The xml-to-string takes a node or node-set and serializes it to a string.And of course if you pass a parameter in then the code needs to reference that parameter somewhere to make use of it so assuming you have a node-set parameter you need e.g. <xsl:template match="/"> <xsl:call-template name="xml-to-string"> <xsl:with-param name="node-set" select="$ManualAlloc"/> </xsl:call-template></xsl:template>
michaelloveusa Posted May 11, 2012 Author Posted May 11, 2012 Hi Martin - Thanks for the info. Sorry for the dumb question. I am slightly xsl challenged. The parameter is a node set. Mike
Recommended Posts
Archived
This topic is now archived and is closed to further replies.